2017-11-25 161 views
0

我有一個工具箱,想要填充。但我沒有做到這一點。我很簡單的問題,我知道,因爲我非常努力地嘗試,但沒有。WPF Dockpanel寬度Stretch in xaml

<StackPanel Orientation="Vertical" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Column="1" Grid.Row="0"> 


      <DockPanel Height="40" HorizontalAlignment="Stretch" Background="#eaeaea" LastChildFill="True"> 

       <StackPanel HorizontalAlignment="Stretch" DockPanel.Dock="Left" Orientation="Vertical"> 

        <Border BorderThickness="1" BorderBrush="#eaeaea" CornerRadius="10" Padding="2" VerticalAlignment="Stretch" > 

         <Grid Width="auto" HorizontalAlignment="Stretch" > 

          <Border Name="mask" Background="#eaeaea" CornerRadius="6,0,0,6" HorizontalAlignment="Stretch" /> 

         <StackPanel Height="30" Margin="2,2,2,2" Name="kucukmenu" HorizontalAlignment="Stretch" Width="auto"> 

           <StackPanel.OpacityMask> 
            <VisualBrush Visual="{Binding ElementName=mask}"/> 
           </StackPanel.OpacityMask> 


          </StackPanel> 

         </Grid> 

        </Border> 

      </StackPanel> 

       <StackPanel Height="40" Orientation="Horizontal" HorizontalAlignment="Right" DockPanel.Dock="Right"> 
        <Button Style="{DynamicResource systembtn}"> 
         <Image Source="images/icons/settings.png" HorizontalAlignment="Right"/> 
        </Button> 
        <Button Style="{DynamicResource systembtn}"> 
         <Image Source="images/icons/minimize.png" HorizontalAlignment="Right" /> 
        </Button> 
        <Button Style="{DynamicResource systembtn}"> 
         <Image Source="images/icons/cancel.png" HorizontalAlignment="Right"/> 
        </Button> 
       </StackPanel> 
      </DockPanel> 

    </StackPanel> 

Now it looks like this

I want to this

回答

1

您可以簡單地使用GridColumnDefinitions

Width="*"手段罷了不亞於區的項目就可以了,這是你的藍區

Width="Auto"意味着只填充物品需要的區域是您的按鈕

你可以找到更多信息通過搜索xaml grid

<Grid Height="40"> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition Width="*" /> 
     <ColumnDefinition Width="Auto" /> 
     <ColumnDefinition Width="Auto" /> 
     <ColumnDefinition Width="Auto" /> 
    </Grid.ColumnDefinitions> 
    <DockPanel Grid.Column="0" Width="100"> 
     <StackPanel HorizontalAlignment="Stretch" DockPanel.Dock="Left" Orientation="Vertical"> 
      <StackPanel.Background> 
       <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> 
        <LinearGradientBrush.RelativeTransform> 
         <TransformGroup> 
          <ScaleTransform CenterY="0.5" CenterX="0.5" /> 
          <SkewTransform CenterY="0.5" CenterX="0.5" /> 
          <RotateTransform Angle="90" CenterY="0.5" CenterX="0.5" /> 
          <TranslateTransform /> 
         </TransformGroup> 
        </LinearGradientBrush.RelativeTransform> 
        <GradientStop Color="#FFBFC5E2" Offset="0" /> 
        <GradientStop Color="#FF123CF5" Offset="1" /> 
       </LinearGradientBrush> 
      </StackPanel.Background> 
     </StackPanel> 
    </DockPanel> 
    <Button Grid.Column="1" Content="btn 1" /> 
    <Button Grid.Column="2" Content="btn 2" /> 
    <Button Grid.Column="3" Content="btn 3" /> 
</Grid> 

如果您需要更復雜的事情要做,你可以使用這個包https://github.com/sourcechord/GridExtra