Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - How to draw a horizontal line without specifying X2??

 
 
Old 08-25-2007   #1 (permalink)
John Taylor


 
 

How to draw a horizontal line without specifying X2??

I want to draw a horizontal line that fills up the entire available width of
a grid cell. I don't want to explicitly specify the line's width (X2). How
do I do this???

<Line Grid.Row="1" Stroke="Gray" StrokeThickness="1" X1="0" X2="200" Y1="1"
Y2="1" />

in above sample, I want to remove the "200" so that the line sizes
automatically when the grid is resized. thanks!


My System SpecsSystem Spec
Old 08-26-2007   #2 (permalink)
Laurent Bugnion, MVP


 
 

Re: How to draw a horizontal line without specifying X2??

Hi,

John Taylor wrote:
Quote:

> I want to draw a horizontal line that fills up the entire available
> width of a grid cell. I don't want to explicitly specify the line's
> width (X2). How do I do this???
>
> <Line Grid.Row="1" Stroke="Gray" StrokeThickness="1" X1="0" X2="200"
> Y1="1" Y2="1" />
>
> in above sample, I want to remove the "200" so that the line sizes
> automatically when the grid is resized. thanks!
X2 is a DependencyProperty, so you can easily bind to the desired value.
For example:

<Grid x:Name="MyGrid">

<Grid.RowDefinitions>
<RowDefinition Height="10"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>

<Line Grid.Row="1"
X1="0"
X2="{Binding ElementName=MyGrid, Path=ActualWidth}"
Stroke="Red"
StrokeThickness="5"
Y1="1"
Y2="1"/>

</Grid>

Note: You must bind to ActualWidth, not to Width. ActualWidth is always
accurate, while Width is what the user entered, so the value may be Auto
or simply not set.

HTH,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft.ch
PhotoAlbum: http://www.galasoft.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
My System SpecsSystem Spec
Old 08-26-2007   #3 (permalink)
John Taylor


 
 

Re: How to draw a horizontal line without specifying X2??

This doesn't seem to work when the grid is resized. Is there anything else I
should be doing?


"Laurent Bugnion, MVP" <galasoft-lb@xxxxxx> wrote in message
news:#ett$jC6HHA.5844@xxxxxx
Quote:

> Hi,
>
> John Taylor wrote:
Quote:

>> I want to draw a horizontal line that fills up the entire available width
>> of a grid cell. I don't want to explicitly specify the line's width (X2).
>> How do I do this???
>>
>> <Line Grid.Row="1" Stroke="Gray" StrokeThickness="1" X1="0" X2="200"
>> Y1="1" Y2="1" />
>>
>> in above sample, I want to remove the "200" so that the line sizes
>> automatically when the grid is resized. thanks!
>
> X2 is a DependencyProperty, so you can easily bind to the desired value.
> For example:
>
> <Grid x:Name="MyGrid">
>
> <Grid.RowDefinitions>
> <RowDefinition Height="10"/>
> <RowDefinition Height="*"/>
> </Grid.RowDefinitions>
>
> <Line Grid.Row="1"
> X1="0"
> X2="{Binding ElementName=MyGrid, Path=ActualWidth}"
> Stroke="Red"
> StrokeThickness="5"
> Y1="1"
> Y2="1"/>
>
> </Grid>
>
> Note: You must bind to ActualWidth, not to Width. ActualWidth is always
> accurate, while Width is what the user entered, so the value may be Auto
> or simply not set.
>
> HTH,
> Laurent
> --
> Laurent Bugnion [MVP ASP.NET]
> Software engineering, Blog: http://www.galasoft.ch
> PhotoAlbum: http://www.galasoft.ch/pictures
> Support children in Calcutta: http://www.calcutta-espoir.ch
My System SpecsSystem Spec
Old 08-27-2007   #4 (permalink)
Laurent Bugnion, MVP


 
 

Re: How to draw a horizontal line without specifying X2??

Hi,

John Taylor wrote:
Quote:

> This doesn't seem to work when the grid is resized. Is there anything
> else I should be doing?
It works fine here. Are you sure you copied my code? The whole example is:

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid x:Name="MyGrid">

<Grid.RowDefinitions>
<RowDefinition Height="10"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>

<Line Grid.Row="1"
X1="0"
X2="{Binding ElementName=MyGrid, Path=ActualWidth}"
Stroke="Red"
StrokeThickness="5"
Y1="1"
Y2="1"/>

</Grid>
</Window>

If you copy this in KaXaml or in XamlPad, you'll see it works.

Greetings,
Laurent
Quote:

>
>
> "Laurent Bugnion, MVP" <galasoft-lb@xxxxxx> wrote in message
> news:#ett$jC6HHA.5844@xxxxxx
Quote:

>> Hi,
>>
>> John Taylor wrote:
Quote:

>>> I want to draw a horizontal line that fills up the entire available
>>> width of a grid cell. I don't want to explicitly specify the line's
>>> width (X2). How do I do this???
>>>
>>> <Line Grid.Row="1" Stroke="Gray" StrokeThickness="1" X1="0" X2="200"
>>> Y1="1" Y2="1" />
>>>
>>> in above sample, I want to remove the "200" so that the line sizes
>>> automatically when the grid is resized. thanks!
>>
>> X2 is a DependencyProperty, so you can easily bind to the desired
>> value. For example:
>>
>> <Grid x:Name="MyGrid">
>>
>> <Grid.RowDefinitions>
>> <RowDefinition Height="10"/>
>> <RowDefinition Height="*"/>
>> </Grid.RowDefinitions>
>>
>> <Line Grid.Row="1"
>> X1="0"
>> X2="{Binding ElementName=MyGrid, Path=ActualWidth}"
>> Stroke="Red"
>> StrokeThickness="5"
>> Y1="1"
>> Y2="1"/>
>>
>> </Grid>
>>
>> Note: You must bind to ActualWidth, not to Width. ActualWidth is
>> always accurate, while Width is what the user entered, so the value
>> may be Auto or simply not set.
>>
>> HTH,
>> Laurent
>> --
>> Laurent Bugnion [MVP ASP.NET]
>> Software engineering, Blog: http://www.galasoft.ch
>> PhotoAlbum: http://www.galasoft.ch/pictures
>> Support children in Calcutta: http://www.calcutta-espoir.ch
>
--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft.ch
PhotoAlbum: http://www.galasoft.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
My System SpecsSystem Spec
Old 10-06-2009   #5 (permalink)
Jeff Pierson


 
 

Use of Stretch="Fill" to make a line fill the available space

The following works for me.

<Line
Grid.Row="2"
Stretch="Fill"
Stroke="Black"
X2="1" />



John Taylor wrote:

How to draw a horizontal line without specifying X2??
25-Aug-07

I want to draw a horizontal line that fills up the entire available width of
a grid cell. I don't want to explicitly specify the line's width (X2). How
do I do this???

<Line Grid.Row="1" Stroke="Gray" StrokeThickness="1" X1="0" X2="200" Y1="1"
Y2="1" />

in above sample, I want to remove the "200" so that the line sizes
automatically when the grid is resized. thanks!

EggHeadCafe - Software Developer Portal of Choice
Convert XML ADO recordset to Table with the DOM
http://www.eggheadcafe.com/tutorials...-recordse.aspx
My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
Corel draw x13 Software
Draw Pad Issues Windows Live
Draw a LINE on a TABCONTROL??? .NET General


Vista Forums 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 Ltd

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