Wpf用户控制规模问题

时间:2010-02-02 15:47:21

标签: c# wpf user-controls scaling

我有一个用户控件,里面有5个矩形形状。我希望能够在使用它时更改此控件的大小,但是当我将它放在设计器中并在那里调整大小时,矩形不会随控件缩放,它们只是被掩盖或者不会扩展。这看起来应该很简单,但它让我望而却步。

<UserControl
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" x:Class="WpfControlLib.CellUserControl"
Height="179.333" Width="160" x:Name="CellControl" mc:Ignorable="d">
<UserControl.Resources>
    <Storyboard x:Key="Ani"/>
</UserControl.Resources>
<UserControl.Triggers>
    <EventTrigger RoutedEvent="FrameworkElement.Loaded">
        <BeginStoryboard Storyboard="{StaticResource Ani}"/>
    </EventTrigger>
</UserControl.Triggers>
<Grid Margin="0,0,8,8" d:LayoutOverrides="HorizontalAlignment">
    <Grid.ColumnDefinitions>
        <ColumnDefinition/>
    </Grid.ColumnDefinitions>
    <Grid x:Name="gridCon" Margin="14,13,8,8">
        <Rectangle x:Name="rectangle" Stroke="Black" Margin="0,0,111,14.333" VerticalAlignment="Bottom" Height="29">
            <Rectangle.Fill>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="Black"/>
                    <GradientStop Color="#FF3B46B5" Offset="1"/>
                </LinearGradientBrush>
            </Rectangle.Fill>
        </Rectangle>
        <Rectangle x:Name="rectangle1" Stroke="Black" Margin="23,0,88,14.333" VerticalAlignment="Bottom" Height="55">
            <Rectangle.Fill>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="Black"/>
                    <GradientStop Color="#FF3B46B5" Offset="1"/>
                </LinearGradientBrush>
            </Rectangle.Fill>
        </Rectangle>
        <Rectangle x:Name="rectangle2" Stroke="Black" Margin="46,0,64.96,14.333" VerticalAlignment="Bottom" Height="77">
            <Rectangle.Fill>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="Black"/>
                    <GradientStop Color="#FF3B46B5" Offset="1"/>
                </LinearGradientBrush>
            </Rectangle.Fill>
        </Rectangle>
        <Rectangle x:Name="rectangle3" Stroke="Black" Margin="69.04,0,41.96,14.333" VerticalAlignment="Bottom" Height="105">
            <Rectangle.Fill>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="Black"/>
                    <GradientStop Color="#FF3B46B5" Offset="1"/>
                </LinearGradientBrush>
            </Rectangle.Fill>
        </Rectangle>
        <Rectangle x:Name="rectangle4" Stroke="Black" Margin="92.04,0,18.96,14.333" VerticalAlignment="Bottom" Height="136">
            <Rectangle.Fill>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="Black"/>
                    <GradientStop Color="#FF3B46B5" Offset="1"/>
                </LinearGradientBrush>
            </Rectangle.Fill>
        </Rectangle>
    </Grid>

</Grid>

1 个答案:

答案 0 :(得分:1)

微软Ben Ronco的回答:

“将根网格放在视图框中”

就像我想的那样简单。