Reputation: 8659
I have a Silverlight user control that has several canvas controls within a Stack Panel. I know that I can set the Width and Height of each canvas panel manually in the Xaml, but I want them to be the same size.
Is there some way I can define a property in a UserControl.Resources location:
<UserControl.Resources>
<Setter Property Name="aWidth" Value="50" />
<Setter Property Name="aHeight" Value="50" />
</UserControl.Resources>
<StackPanel Orientation="Horizontal">
<Canvas x:Name="canvas1" Width="{StaticResource aWidth}" Height="{StaticResource aHeight}" />
<Canvas x:Name="canvas2" Width="{StaticResource aWidth}" Height="{StaticResource aHeight}" />
</StackPanel>
so that each panel is the same width and height and I only have to set it once.
Upvotes: 1
Views: 168
Reputation: 3343
Add this xml namespace declaration to the root of your Xaml:
xmlns:sys="clr-namespace:System;assembly=mscorlib"
And change your resources to look like the following:
<UserControl.Resources>
<sys:Double x:Key="aWidth" >50</sys:Double>
<sys:Double x:Key="aHeight" >50</sys:Double>
</UserControl.Resources>
Now you should be able to use the {StaticResource}s the way you want.
Upvotes: 1
Reputation: 189505
Use a Grid instead
<Grid Width="600" Height="300">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Canvas x:Name="canvas1" />
<Canvas x:Name="canvas2" Grid.Column="1" />
</Grid>
Both the Canvas's will have the height of 300 and width of 300.
Upvotes: 0