![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 Specs![]() |
| | #3 (permalink) |
| | 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 Specs![]() |
| | #4 (permalink) |
| | 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 Specs![]() |
| | #5 (permalink) |
| | 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 Specs![]() |
| | #6 (permalink) |
| | 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 Specs![]() |