Solved

WPF User Control Polyline Size Wrong

Posted on 2013-12-14
13
522 Views
Last Modified: 2013-12-23
I have created a custom user control for WPF use with VB.net for the code behind.  Essentially, it is a polyline that snaps to connect other custom controls.  The Polyline is created via code at runtime.  It works great vertically and if it has both width and height.  However if it is horizontal or flat, it distorts.  The thicker the line, the worse it distorts.  It distorts on both ends with neither beginning or ending in the right location.

Any ideas on how to fix?  It looks like a stretch issue but it doesn't stretch completely.
0
Comment
Question by:Tesla428
  • 8
  • 5
13 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 39721146
Can you give us a small bit of code to highlight the problem, please?
0
 

Author Comment

by:Tesla428
ID: 39727285
Screen shot of the issue
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 39727300
What does the XAML/code look like?
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:Tesla428
ID: 39727404
Public Class Pipe
    Private mLine As New Polyline
    Private mOutline As New Polyline

    Public Sub New(ByVal First As Point, ByVal Last As Point)
        InitializeComponent()

        With mOutline
            .Stroke = Brushes.Red
            .HorizontalAlignment = HorizontalAlignment.Left
            .VerticalAlignment = VerticalAlignment.Top
            .StrokeThickness = 5
            .Stretch = Stretch.None
        End With

        With mLine
            .Stroke = Brushes.Black
            .HorizontalAlignment = HorizontalAlignment.Left
            .VerticalAlignment = VerticalAlignment.Top
            .StrokeThickness = 2
            .Stretch = Stretch.None
         
            If First.X = Last.X Or First.Y = Last.Y Then
                .Points.Add(First)
                .Points.Add(Last)
            End If
            If First.X > Last.X Then
                .Points.Add(First)
                .Points.Add(New Point(First.X, Last.Y))
                .Points.Add(Last)
            End If
            If First.X < Last.X Then
                .Points.Add(First)
                .Points.Add(New Point(First.X, Last.Y))
                .Points.Add(Last)
            End If
        End With

        For Each SharePoint As Point In mLine.Points
            mOutline.Points.Add(SharePoint)
        Next

        grdPipe.Children.Add(mOutline)
        grdPipe.Children.Add(mLine)

    End Sub

End Class

Open in new window


Polyline Class VB Code Behind
0
 

Author Comment

by:Tesla428
ID: 39727406
<UserControl x:Class="Pipe"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300" HorizontalContentAlignment="Left" VerticalContentAlignment="Top" HorizontalAlignment="Left" VerticalAlignment="Top">
    <Grid Name="grdPipe"></Grid> 
</UserControl>

Open in new window


XAML For the Polylines
0
 

Author Comment

by:Tesla428
ID: 39727412
<Window x:Class="MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Working" Height="362" Width="426" WindowState="Maximized">
    <Grid >
        <DockPanel x:Name="LayoutRoot"             LastChildFill="True">
            <StackPanel  Height="40" DockPanel.Dock="Top" Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Top">
                <Slider x:Name="ZoomSlider"                Minimum="1" Value="1" Maximum="5" Height="26" VerticalAlignment="Top" HorizontalAlignment="Left" Width="85" Margin="10,10,0,0" />
                <TextBlock Height="22" Name="TextBlock1" Text="{Binding ElementName=ZoomSlider, Path=Value, StringFormat='Current Zoom: \{0:0.0\}x'}" Margin="12" />
                <CheckBox Content="Show GridLines" Height="16" Name="chkSnapLines" />
                
            </StackPanel>
            <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" HorizontalAlignment="Left" VerticalAlignment="Top">
                <Grid Name="grdMain" VerticalAlignment="Top" HorizontalAlignment="Left">
                    <Grid.LayoutTransform>
                        <ScaleTransform ScaleX="{Binding Path=Value, ElementName=ZoomSlider}"
                                        ScaleY="{Binding Path=Value,ElementName=ZoomSlider}" />
                    </Grid.LayoutTransform>
                   </Grid>
            </ScrollViewer>
        </DockPanel>

    </Grid>
</Window>

Open in new window


XAML for Main Window
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 39727422
I read your initial question, and I see the screen shot, but I still don't quite understand the issue.  Are you having a problem with calculating the length of each line, with respect to the aspect ratio for the drawing surface?
0
 

Author Comment

by:Tesla428
ID: 39727449
No, I need the lines to start and stop at a specific location.  They do this correctly in every instance if they have a vertical component.  However, if the are completely flat they stretch.  Both the start point and end point are both affected and if the line is wider, it gets even worse.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 39727516
If you believe that this is a stretch issue, what is the width of the drawing surface, compared to it's height?  If it is square, I wouldn't think that this would be a stretching issue.
0
 

Author Comment

by:Tesla428
ID: 39727546
Are you able to replicate the issue?  Even on a simple polyline?  I am service packing visual studio and loading all available updates.  I don't think it is video driver related.
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 39727651
You are using a ScaleTransform.  Does this happen when Zoom is at 1.0?
0
 

Assisted Solution

by:Tesla428
Tesla428 earned 0 total points
ID: 39727664
Found it.  Bad Logic in the if/then statements.  Everything renders fine.
0
 

Author Closing Comment

by:Tesla428
ID: 39735710
I was able to locate it on my own.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Exit the loop 4 42
Search an image for an image 3 29
SQL Help 27 43
Expression Evaluater 3 24
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question