2010-02-02 86 views
2

我有一個用戶控件,其中有5個矩形形狀。我希望能夠在使用該控件時更改此控件的大小,但當我將它放入設計器並將其調整大小時,矩形不會與控件一起縮放,它們只會隱藏或不會展開。這看起來應該是非常簡單的,但它讓我無法迴避。Wpf用戶控制規模問題

<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

從微軟的奔龍科答:

「把根格在視框」

一樣簡單,因爲我認爲這將是。