Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7491303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:57:41+00:00 2026-05-29T15:57:41+00:00

I have some very simple code that ‘correctly’ draws a short vertical black line

  • 0

I have some very simple code that ‘correctly’ draws a short vertical black line on a 1024×768 blue canvas in WPF (well in Silverlight 4).

            <UserControl x:Class="SimpleCanvas.MainPage"
                xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                mc:Ignorable="d"
                Loaded="UserControl_Loaded">
                <Grid x:Name="LayoutRoot" Background="White">
                    <Canvas x:Name="PathCanvas" Width="1024" Height="768" Background="Blue"/>
                </Grid>
            </UserControl>

and here’s the code-behind

            private void UserControl_Loaded(object sender, RoutedEventArgs e)
            {
                var myPathFigure = new PathFigure
                {
                    StartPoint = new Point(492, 748)
                };

                var line1 = new LineSegment
                {
                    Point = new Point(492, 708)
                };

                myPathFigure.Segments.Add(line1);

                var myPathGeometry = new PathGeometry();
                myPathGeometry.Figures.Add(myPathFigure);

                var myPath = new Path
                {
                    Data = myPathGeometry,
                    Stretch = Stretch.Fill,
                    Stroke = new SolidColorBrush(Color.FromArgb(0xFF, 0x0, 0x0, 0x0)),
                    StrokeThickness = 10
                };

                PathCanvas.Children.Add(myPath);
            }

Now if I change the end-point of the line segment, so that instead of just changing the Y from the start-point I also change the X, albeit by only one pixel, the whole line is rendered in the top left of the canvas. Here’s the revised code-behind.

            private void UserControl_Loaded(object sender, RoutedEventArgs e)
            {
                var myPathFigure = new PathFigure
                {
                    StartPoint = new Point(492, 748)
                };

                var line1 = new LineSegment
                {
                    Point = new Point(491, 708)
                };

                myPathFigure.Segments.Add(line1);

                var myPathGeometry = new PathGeometry();
                myPathGeometry.Figures.Add(myPathFigure);

                var myPath = new Path
                {
                    Data = myPathGeometry,
                    Stretch = Stretch.Fill,
                    Stroke = new SolidColorBrush(Color.FromArgb(0xFF, 0x0, 0x0, 0x0)),
                    StrokeThickness = 10
                };

                PathCanvas.Children.Add(myPath);
            }

If both rendered in the centre-bottom of the canvas, or both rendered in the top left of the canvas, I could understand. But I do not understand why the first code block causes the line to render centre-bottom and the second code block causes the line to render top-left.

Note that I’m not using Canvas.Top or Canvas.Left.

Any insight gratefully received!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T15:57:42+00:00Added an answer on May 29, 2026 at 3:57 pm

    The problem here is that you are creating the Path with the Stretch property set to Stretch.Fill. I imagine you want to leave the Path with Stretch set to the default, Stretch.None.

    The reason why the first code-block causes the line to be rendered in the centre of the canvas is because both points in its single LineSegment have the same X-coordinate, and hence the Path has a width of 0. Clearly an element with width 0 can’t be stretched horizontally. Silverlight could attempt to stretch your Path vertically, since it has nonzero height, but it seems it chooses not to.

    Similarly, if you draw a horizontal line (so the Path has height 0), Silverlight doesn’t stretch the line either.

    In your second code-block, when you’ve change the X-coordinate, even by 1 pixel, you give the Path a non-zero width and height. Silverlight can then stretch it to fill the entire Canvas.

    Note that the Path control itself, as the container for the various path segments, is being stretched, not the individual line segments that comprise it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some very simple code below that I can't get to validate on
I have some very simple javascript code that looks like this: var newWindow =
I have some very simple code to generate an assembly and invoke a method
I have some VERY simple code to return the title for a section header:
I have a very simple XAML form, that has one namespace definition. For some
I have some very basic semaphore code that works great on Linux, but cannot
I have a PHP form that needs some very simple validation on submit. I'd
I have a very simple piece of code that I used in previous versions
I have some very simple code to do with handlers: Handler seconds=new Handler() {
I have a very simple bit of code that won't work, and have no

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.