Windows Vista Forums
Vista Forums Home Join Vista Forums Webcasts Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > Avalon

How to draw a line without explicitly specifying its coordinates

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 02-02-2006   #1 (permalink)
Pascal Bourque
Guest


 

How to draw a line without explicitly specifying its coordinates

Hi,

I would like to draw horizontal dashed lines between elements in a
vertical StackPanel, letting the StackPanel layout the lines
appropriately (i.e. determine their width). I can easily draw a solid
line using a Rectangle shape like so:

<StackPanel>
<Button>Foo</Button>
<Rectangle Stroke="Red" StrokeThickness="2" />
<Button>Foo</Button>
<Rectangle Stroke="Red" StrokeThickness="2" />
<Button>Foo</Button>
</StackPanel>

But if I specify a StrokeDashArray to those "flat" rectangles, the dash
effect is't visible and the lines are still drawn solid:

<StackPanel>
<Button>toto</Button>
<Rectangle Stroke="Red" StrokeThickness="2" StrokeDashArray="2" />
<Button>toto</Button>
<Rectangle Stroke="Red" StrokeThickness="2" StrokeDashArray="2" />
<Button>toto</Button>
</StackPanel>

If I specify a height to those rectangles, I can see the StrokeDashArray
in action.

Ideally, I'd like to use a Line shape for this purpose, but the problem
is that Lines seem to require explicit start/end point coordinates
(X1,Y1 and X2,Y2) to draw anything. This prevents me from letting the
StackPanel determine their width automatically...


I feel this should be easy to achieve and that I am missing something
obvious, but I just can't figure out what...

Thanks!

Pascal

My System SpecsSystem Spec
Old 02-02-2006   #2 (permalink)
viliescu
Guest


 

RE: How to draw a line without explicitly specifying its coordinates

You can try to create a custom control:
- it will contain just the line as a child
- override Measure/Arrange to position the line
--
Valentin Iliescu [MVP C#]


"Pascal Bourque" wrote:

> Hi,
>
> I would like to draw horizontal dashed lines between elements in a
> vertical StackPanel, letting the StackPanel layout the lines
> appropriately (i.e. determine their width). I can easily draw a solid
> line using a Rectangle shape like so:
>
> <StackPanel>
> <Button>Foo</Button>
> <Rectangle Stroke="Red" StrokeThickness="2" />
> <Button>Foo</Button>
> <Rectangle Stroke="Red" StrokeThickness="2" />
> <Button>Foo</Button>
> </StackPanel>
>
> But if I specify a StrokeDashArray to those "flat" rectangles, the dash
> effect is't visible and the lines are still drawn solid:
>
> <StackPanel>
> <Button>toto</Button>
> <Rectangle Stroke="Red" StrokeThickness="2" StrokeDashArray="2" />
> <Button>toto</Button>
> <Rectangle Stroke="Red" StrokeThickness="2" StrokeDashArray="2" />
> <Button>toto</Button>
> </StackPanel>
>
> If I specify a height to those rectangles, I can see the StrokeDashArray
> in action.
>
> Ideally, I'd like to use a Line shape for this purpose, but the problem
> is that Lines seem to require explicit start/end point coordinates
> (X1,Y1 and X2,Y2) to draw anything. This prevents me from letting the
> StackPanel determine their width automatically...
>
>
> I feel this should be easy to achieve and that I am missing something
> obvious, but I just can't figure out what...
>
> Thanks!
>
> Pascal
>

My System SpecsSystem Spec
Old 02-04-2006   #3 (permalink)
Adam Smith [MS]
Guest


 

Re: How to draw a line without explicitly specifying its coordinates

Perhaps using the Path Element will work - it's a tad more complicated, but
it also has a few more features.

<Path Data="M0,0 1,0" Stroke="Red" StrokeThickness="2" Height="2"
Stretch="Fill"/>

In this case, the Path in a vacuum (or, say, in a Canvas) will just be a
line from 0,0 to 1,0. However, setting Stretch to Fill means that we will
stretch the underlying geometry (before applying the Stroke) to fill the
layout space reserved.

-Adam Smith [MS]

"viliescu" <viliescu@discussions.microsoft.com> wrote in message
news:02EE361F-1889-4812-9A4F-E2A4C4119307@microsoft.com...
> You can try to create a custom control:
> - it will contain just the line as a child
> - override Measure/Arrange to position the line
> --
> Valentin Iliescu [MVP C#]
>
>
> "Pascal Bourque" wrote:
>
>> Hi,
>>
>> I would like to draw horizontal dashed lines between elements in a
>> vertical StackPanel, letting the StackPanel layout the lines
>> appropriately (i.e. determine their width). I can easily draw a solid
>> line using a Rectangle shape like so:
>>
>> <StackPanel>
>> <Button>Foo</Button>
>> <Rectangle Stroke="Red" StrokeThickness="2" />
>> <Button>Foo</Button>
>> <Rectangle Stroke="Red" StrokeThickness="2" />
>> <Button>Foo</Button>
>> </StackPanel>
>>
>> But if I specify a StrokeDashArray to those "flat" rectangles, the dash
>> effect is't visible and the lines are still drawn solid:
>>
>> <StackPanel>
>> <Button>toto</Button>
>> <Rectangle Stroke="Red" StrokeThickness="2" StrokeDashArray="2" />
>> <Button>toto</Button>
>> <Rectangle Stroke="Red" StrokeThickness="2" StrokeDashArray="2" />
>> <Button>toto</Button>
>> </StackPanel>
>>
>> If I specify a height to those rectangles, I can see the StrokeDashArray
>> in action.
>>
>> Ideally, I'd like to use a Line shape for this purpose, but the problem
>> is that Lines seem to require explicit start/end point coordinates
>> (X1,Y1 and X2,Y2) to draw anything. This prevents me from letting the
>> StackPanel determine their width automatically...
>>
>>
>> I feel this should be easy to achieve and that I am missing something
>> obvious, but I just can't figure out what...
>>
>> Thanks!
>>
>> Pascal
>>



My System SpecsSystem Spec
Old 02-04-2006   #4 (permalink)
Pascal Bourque
Guest


 

Re: How to draw a line without explicitly specifying its coordinates

I did not try with the Path, but your suggestion led me to try this:

<Line X1="0"
Y1="0"
X2="1"
Y2="0"
Stroke="Red"
StrokeDashArray="2"
Stretch="Fill" />

And it works!

The key is to use 0,0-1,0 as coordinates for the Line, and specify
Stretch=Fill.

Thanks a lot!

Pascal

Adam Smith [MS] wrote:
> Perhaps using the Path Element will work - it's a tad more complicated, but
> it also has a few more features.
>
> <Path Data="M0,0 1,0" Stroke="Red" StrokeThickness="2" Height="2"
> Stretch="Fill"/>
>
> In this case, the Path in a vacuum (or, say, in a Canvas) will just be a
> line from 0,0 to 1,0. However, setting Stretch to Fill means that we will
> stretch the underlying geometry (before applying the Stroke) to fill the
> layout space reserved.
>
> -Adam Smith [MS]

My System SpecsSystem Spec
Old 02-04-2006   #5 (permalink)
Adam Smith [MS]
Guest


 

Re: How to draw a line without explicitly specifying its coordinates

Oh, yeah, that's even simpler - forgot that Line did that too.

Happy to help,
-Adam Smith [MS]

"Pascal Bourque" <bourquep@xceedsoft.com> wrote in message
news:%23o7QX3CKGHA.4020@TK2MSFTNGP10.phx.gbl...
>I did not try with the Path, but your suggestion led me to try this:
>
> <Line X1="0"
> Y1="0"
> X2="1"
> Y2="0"
> Stroke="Red"
> StrokeDashArray="2"
> Stretch="Fill" />
>
> And it works!
>
> The key is to use 0,0-1,0 as coordinates for the Line, and specify
> Stretch=Fill.
>
> Thanks a lot!
>
> Pascal
>
> Adam Smith [MS] wrote:
>> Perhaps using the Path Element will work - it's a tad more complicated,
>> but it also has a few more features.
>>
>> <Path Data="M0,0 1,0" Stroke="Red" StrokeThickness="2" Height="2"
>> Stretch="Fill"/>
>>
>> In this case, the Path in a vacuum (or, say, in a Canvas) will just be a
>> line from 0,0 to 1,0. However, setting Stretch to Fill means that we
>> will stretch the underlying geometry (before applying the Stroke) to fill
>> the layout space reserved.
>>
>> -Adam Smith [MS]



My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to draw a horizontal line without specifying X2?? John Taylor Avalon 3 08-27-2007 01:36 AM
Texture Coordinates across multiple meshes Avery Z Avalon 1 10-19-2006 07:29 PM
How do I explicitly set the CurrentCulture? =?Utf-8?B?Um9tYW4gS3V6bWlu?= PowerShell 7 09-11-2006 03:12 PM
How do I explicitly cause a UAC elevation prompt? =?Utf-8?B?S2V2aW4gU291dGhlcm4=?= Vista security 2 09-07-2006 03:42 PM
How to get the coordinates of a FrameworkElement? Jason Dolinger Avalon 2 01-31-2006 07:00 AM


Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51