Is there a way of resizing controls in a Silverlight 4 OOB app?
I am new to开发者_运维技巧 Silverlight/XAML so apologies if this is an obvious question.
How can you detect when the OOB window is resized and resize your own controls to fit the new window size?
In Silverlight (regardless of OOB or not) you wouldn't normally need to detect window resizing to perform your own resizing. Using the correct panel types sorts that out for you.
For example:-
<UserControl x:Class="SilverlightApplication1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Rectangle Fill="Green" Grid.Row="0" Grid.Column="0" />
<Rectangle Fill="Red" Grid.Row="0" Grid.Column="1" />
<Rectangle Fill="Yellow" Grid.Row="1" Grid.Column="0" />
<Rectangle Fill="Blue" Grid.Row="1" Grid.Column="1" />
</Grid>
</UserControl>
Here the four rectangles divide up the window into quarters. It may be worth your while spending a little time review the documentation for the various panel types such as Grid
, Canvas
and StackPanel
to get a feel for how each works.
精彩评论