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 - WPF Custom Control Sizing?

 
 
Old 11-20-2006   #1 (permalink)
john


 
 

WPF Custom Control Sizing?

All:

I am writing a simple Custom Control in WPF. I intent to put this
control on a WBP Grid panel via:

Grid.SetRow(myControl, row);
Grid.SetColumn(myControl, col);

I would like the control to size itself to the "cell" in the grid where
it is placed. When the grid is resized, the control should resize
itself to the new size of the cell as well.

Is this the default behavior?
If not, how do I specifiy this in XAML?
In C#?

Many thanks,
John


My System SpecsSystem Spec
Old 11-20-2006   #2 (permalink)
Stoitcho Goutsev \(100\)


 
 

Re: WPF Custom Control Sizing?

john,

I think this should be the default behavior.
If you want to specify this explicitly set VerticalAlignment and
HorizontalAlignment to *Stretch*.


--
HTH
Stoitcho Goutsev (100)

"john" <puopolo@gmail.com> wrote in message
news:1164050093.218691.119770@h48g2000cwc.googlegroups.com...
> All:
>
> I am writing a simple Custom Control in WPF. I intent to put this
> control on a WBP Grid panel via:
>
> Grid.SetRow(myControl, row);
> Grid.SetColumn(myControl, col);
>
> I would like the control to size itself to the "cell" in the grid where
> it is placed. When the grid is resized, the control should resize
> itself to the new size of the cell as well.
>
> Is this the default behavior?
> If not, how do I specifiy this in XAML?
> In C#?
>
> Many thanks,
> John
>



My System SpecsSystem Spec
Old 11-20-2006   #3 (permalink)
john


 
 

Re: WPF Custom Control Sizing?

Stoitcho:

When the control is first added to the grid, it fills the "cell"
correctly - but when the grid is resized, the control stays its
original size, positioned centered in the cell.

Other thoughts?

Best,
John



Unfortunatelt,
Stoitcho Goutsev (100) wrote:
> john,
>
> I think this should be the default behavior.
> If you want to specify this explicitly set VerticalAlignment and
> HorizontalAlignment to *Stretch*.
>
>
> --
> HTH
> Stoitcho Goutsev (100)
>
> "john" <puopolo@gmail.com> wrote in message
> news:1164050093.218691.119770@h48g2000cwc.googlegroups.com...
> > All:
> >
> > I am writing a simple Custom Control in WPF. I intent to put this
> > control on a WBP Grid panel via:
> >
> > Grid.SetRow(myControl, row);
> > Grid.SetColumn(myControl, col);
> >
> > I would like the control to size itself to the "cell" in the grid where
> > it is placed. When the grid is resized, the control should resize
> > itself to the new size of the cell as well.
> >
> > Is this the default behavior?
> > If not, how do I specifiy this in XAML?
> > In C#?
> >
> > Many thanks,
> > John
> >


My System SpecsSystem Spec
Old 11-20-2006   #4 (permalink)
Laurent Bugnion


 
 

Re: WPF Custom Control Sizing?

Hi John,

john wrote:
> Stoitcho:
>
> When the control is first added to the grid, it fills the "cell"
> correctly - but when the grid is resized, the control stays its
> original size, positioned centered in the cell.
>
> Other thoughts?
>
> Best,
> John


What version of the framework do you have? It changed after the May CTP
IIRC. Now the default value for the Alignments shoud be Stretch, which
should be what you want. I just tested for you in the September CTP
(still didn't have time to install the November CTP) and this does
exactly what you specify:

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

<Grid Name="pnGrid">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>

<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>

<Canvas Background="Blue" Grid.Column="1" Grid.Row="1">
<TextBlock Text="Hello" />
</Canvas>

</Grid>
</Window>

I also tested this in C#, same result:

public partial class Window1 : System.Windows.Window
{

public Window1()
{
InitializeComponent();

Canvas pnCanvas2 = new Canvas();
pnCanvas2.Background = Brushes.Red;
TextBlock lbl = new TextBlock();
lbl.Text = "Hello2";
pnCanvas2.Children.Add( lbl );

pnGrid.Children.Add( pnCanvas2 );

Grid.SetColumn( pnCanvas2, 2 );
Grid.SetRow( pnCanvas2, 2 );
}
}

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
My System SpecsSystem Spec
Old 11-22-2006   #5 (permalink)
john


 
 

Re: WPF Custom Control Sizing?

All:

Sorry - my bad. In the XAML, I had a left-over Width and Height
specified, so WPF was doing what I told it to do by constraining the
width and height of the control. Once I removed the width and height
(in essence giving the control no specific values) and set the
alignments to Stretch, it worked great.

Thank you!

John


Laurent Bugnion wrote:
> Hi John,
>
> john wrote:
> > Stoitcho:
> >
> > When the control is first added to the grid, it fills the "cell"
> > correctly - but when the grid is resized, the control stays its
> > original size, positioned centered in the cell.
> >
> > Other thoughts?
> >
> > Best,
> > John

>
> What version of the framework do you have? It changed after the May CTP
> IIRC. Now the default value for the Alignments shoud be Stretch, which
> should be what you want. I just tested for you in the September CTP
> (still didn't have time to install the November CTP) and this does
> exactly what you specify:
>
> <Window x:Class="WindowsApplication1.Window1"
> xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
> xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
> Title="WindowsApplication1" Height="300" Width="300"
> >

> <Grid Name="pnGrid">
> <Grid.ColumnDefinitions>
> <ColumnDefinition />
> <ColumnDefinition />
> <ColumnDefinition />
> </Grid.ColumnDefinitions>
>
> <Grid.RowDefinitions>
> <RowDefinition />
> <RowDefinition />
> <RowDefinition />
> </Grid.RowDefinitions>
>
> <Canvas Background="Blue" Grid.Column="1" Grid.Row="1">
> <TextBlock Text="Hello" />
> </Canvas>
>
> </Grid>
> </Window>
>
> I also tested this in C#, same result:
>
> public partial class Window1 : System.Windows.Window
> {
>
> public Window1()
> {
> InitializeComponent();
>
> Canvas pnCanvas2 = new Canvas();
> pnCanvas2.Background = Brushes.Red;
> TextBlock lbl = new TextBlock();
> lbl.Text = "Hello2";
> pnCanvas2.Children.Add( lbl );
>
> pnGrid.Children.Add( pnCanvas2 );
>
> Grid.SetColumn( pnCanvas2, 2 );
> Grid.SetRow( pnCanvas2, 2 );
> }
> }
>
> HTH,
> Laurent
> --
> Laurent Bugnion, GalaSoft
> Software engineering: http://www.galasoft-LB.ch
> PhotoAlbum: http://www.galasoft-LB.ch/pictures
> Support children in Calcutta: http://www.calcutta-espoir.ch


My System SpecsSystem Spec
Old 11-22-2006   #6 (permalink)
Laurent Bugnion


 
 

Re: WPF Custom Control Sizing?

Hi John,

john wrote:
> All:
>
> Sorry - my bad. In the XAML, I had a left-over Width and Height
> specified, so WPF was doing what I told it to do by constraining the
> width and height of the control. Once I removed the width and height
> (in essence giving the control no specific values) and set the
> alignments to Stretch, it worked great.
>
> Thank you!
>
> John


Happy to read that. Thanks for the feedback.

Greetings,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
My System SpecsSystem Spec
 

Thread Tools



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