Silverlight的SharedSizeGroup

时间:2013-04-30 06:35:21

标签: c# wpf silverlight xaml

在Wpf中,我们有SharedSizeGroup属性来共享Grids之间的大小,比如列。有人知道Silverlight中的类似功能支持吗?

2 个答案:

答案 0 :(得分:0)

共享大小调整最好使用Silverlight中的元素属性绑定实现。只需将所有共享大小的元素绑定到另一个元素的宽度/高度即可。

请参阅以下内容:

<UserControl x:Class="SLTestApp.MainPage"
       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
       xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
       xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
       xmlns:ext="clr-namespace:System.Windows.Controls.Extensions;assembly=System.Windows.Controls.Extensions"
       mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">

    <Grid x:Name="LayoutRoot" Background="White" ext:SharedSize.IsSharedSizeScope="True">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid x:Name="firstfirstGrid" Grid.Row="0">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"  ext:SharedSize.SharedSizeGroup="A"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" ext:SharedSize.SharedSizeGroup="A"/>
            </Grid.ColumnDefinitions>
            <Border BorderBrush="Green" BorderThickness="2">
                <TextBlock x:Name="txtFirstFirst" >
                    <Run>aa</Run>
                    <LineBreak />
                    <Run>aa</Run>
                </TextBlock>
            </Border>
        </Grid>
        <Grid x:Name="firstsecondGrid" Grid.Row="1">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"  ext:SharedSize.SharedSizeGroup="A"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" ext:SharedSize.SharedSizeGroup="A"/>
            </Grid.ColumnDefinitions>
            <Border BorderBrush="Blue" BorderThickness="2">
                <TextBlock Text="aaaaaaaaaaaaaaaa" />
            </Border>
        </Grid>

    </Grid>
</UserControl>

Link Referance:

http://die-rooter.de/ITworks/archives/27-SharedSize-Grid-with-Silverlight.html

希望它有用。

答案 1 :(得分:0)

<UserControl x:Class="SLTestApp.MainPage"
       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
       xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
       xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
       xmlns:ext="clr-namespace:System.Windows.Controls.Extensions;assembly=System.Windows.Controls.Extensions"
       mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">

    <Grid x:Name="LayoutRoot" Background="White" ext:SharedSize.IsSharedSizeScope="True">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid x:Name="firstfirstGrid" Grid.Row="0">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"  ext:SharedSize.SharedSizeGroup="A"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" ext:SharedSize.SharedSizeGroup="A"/>
            </Grid.ColumnDefinitions>
            <Border BorderBrush="Green" BorderThickness="2">
                <TextBlock x:Name="txtFirstFirst" >
                    <Run>aa</Run>
                    <LineBreak />
                    <Run>aa</Run>
                </TextBlock>
            </Border>
        </Grid>
        <Grid x:Name="firstsecondGrid" Grid.Row="1">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"  ext:SharedSize.SharedSizeGroup="A"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" ext:SharedSize.SharedSizeGroup="A"/>
            </Grid.ColumnDefinitions>
            <Border BorderBrush="Blue" BorderThickness="2">
                <TextBlock Text="aaaaaaaaaaaaaaaa" />
            </Border>
        </Grid>

    </Grid>
</UserControl>