2

我有一个用户控件,其中包含 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>

4

1 回答 1

1

来自微软的 Ben Ronco 的回答:

“将根网格放入 Viewbox”

就像我想象的那样简单。

于 2010-02-02T20:07:23.157 回答