Solved

WPF User Control Polyline Size Wrong

Posted on 2013-12-14
13
509 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
Comment Utility
Can you give us a small bit of code to highlight the problem, please?
0
 

Author Comment

by:Tesla428
Comment Utility
Screen shot of the issue
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
What does the XAML/code look like?
0
 

Author Comment

by:Tesla428
Comment Utility
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
Comment Utility
<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
Comment Utility
<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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
You are using a ScaleTransform.  Does this happen when Zoom is at 1.0?
0
 

Assisted Solution

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

Author Closing Comment

by:Tesla428
Comment Utility
I was able to locate it on my own.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Open a folder with partial name 14 28
SQl help with selection 14 44
C# code editing and collaboration 3 40
VB.NET HttpWebRequest 12 30
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now