?
Solved

WPF User Control Polyline Size Wrong

Posted on 2013-12-14
13
Medium Priority
?
546 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 

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 2000 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

Docker-Compose to Simplify Multi-Container Builds

Our veteran DevOps Author takes you through how to build a multi-container environment, managed with a single utility in order to simplify your deployments.

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

777 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