Solved

WPF User Control Polyline Size Wrong

Posted on 2013-12-14
13
532 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
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…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

733 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