Resize Controls in Canvas

Hi,

I want to use Canvas Panel in XamlBrowser Application And whenever my page is going to resize according to that my controls are also resized ...

Can anyone guide me what to write in .xaml file and i don't want to write a single line in Page1.xaml.cs file... Code must be in Pag1.xaml file only....

Thanks in Advance..............



Answer this question

Resize Controls in Canvas

  • akshah

    you could use binding to control the height/width of the controls

    so if the page/canvas height is changed and supose the controls (textblock) height is 1/2 of the page/canvas you could use a converter along with the binding.

    <TextBlock Height="{Binding ElementName=tb1, Path=ActualHeight, Converter={StaticResource JScript}, ConverterParameter=Int32.Parse(values[0])/2}" Background="Red"/>

    The converter can be found here

    http://blogs.msdn.com/llobo/archive/2006/11/13/Arithmetic-operations-in-Xaml.aspx


  • Douglas Penna

    If you choose Grid instead of Canvas, you'll get many of the autoresizing/layout capabilities you are asking for.

    For example:

    <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Grid >
    <Grid.ColumnDefinitions>
    <ColumnDefinition Width="Auto"/>
    <ColumnDefinition Width="*"/>
    <ColumnDefinition Width=".5in"/>
    <ColumnDefinition Width="2*"/>
    <ColumnDefinition Width=".5in"/>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
    <RowDefinition Height="Auto"/>
    <RowDefinition Height="1*"/>
    <RowDefinition Height=".26in"/>
    <RowDefinition Height="2*"/>
    <RowDefinition Height=".26in"/>
    </Grid.RowDefinitions>
    <Rectangle Fill="#FFFFFFFF" Stroke="#FF000000" Margin="1.455,2.911,2.771,2.809" Grid.Column="1" Grid.Row="1"/>
    <Rectangle Fill="#FFFFFFFF" Stroke="#FF000000" Margin="4.371,1.498,1.456,2.911" Grid.Column="3" Grid.Row="3"/>
    <Button Margin="0,0,2.912,1.089" Content="Button" MinWidth="75"/>
    </Grid>
    </Page>

    Blend and Cider both have good Grid editing experiences.

    Thanks, Rob Relyea
    Program Manager, WPF Team
    http://rrelyea.spaces.live.com


  • rhansen

    Hi Rob Relyea,

    I have code for Grid..... i need code for canvas....and performs same operation........


  • Resize Controls in Canvas