【问题标题】:Wpf User Control scale problemWpf用户控制比例问题
【发布时间】:2010-02-02 15:47:20
【问题描述】:

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

【问题讨论】:

    标签: c# wpf user-controls scaling


    【解决方案1】:

    来自微软的 Ben Ronco 的回答:

    "将根 Grid 放入 Viewbox"

    就像我想象的那样简单。

    【讨论】:

      猜你喜欢
      • 2015-04-04
      • 1970-01-01
      • 2010-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多