5
A
回答
3
一個簡單的選擇是僅重疊控件,然後玩弄邊緣
<Grid>
<GroupBox Header="Title" Margin="0,3,0,0" />
<StackPanel Orientation="Horizontal"
VerticalAlignment="Top" HorizontalAlignment="Right" Margin="0,0,10,0">
<Button Margin="2" Content="Suchen"/>
<Button Margin="2" Content="Neu"/>
</StackPanel>
</Grid>
如果你想要一個可重用的風格,那麼你就需要提取的GroupBox的控件模板和修改。像
<Page.Resources>
<BorderGapMaskConverter x:Key="BorderGapMaskConverter"/>
<Style x:Key="GroupBoxStyle1" TargetType="{x:Type GroupBox}">
<Setter Property="BorderBrush" Value="#D5DFE5"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupBox}">
<Grid SnapsToDevicePixels="true">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="6"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="6"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="6"/>
</Grid.RowDefinitions>
<Border BorderBrush="Transparent" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Grid.ColumnSpan="4" Grid.Column="0" CornerRadius="4" Grid.Row="1" Grid.RowSpan="3"/>
<Border x:Name="Header" Grid.Column="1" Padding="3,1,3,0" Grid.Row="0" Grid.RowSpan="2">
<ContentPresenter ContentSource="Header" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</Border>
<ContentPresenter Grid.ColumnSpan="2" Grid.Column="1" Margin="{TemplateBinding Padding}" Grid.Row="2" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
<Border BorderBrush="White" BorderThickness="{TemplateBinding BorderThickness}" Grid.ColumnSpan="4" CornerRadius="4" Grid.Row="1" Grid.RowSpan="3">
<Border.OpacityMask>
<MultiBinding ConverterParameter="7" Converter="{StaticResource BorderGapMaskConverter}">
<Binding ElementName="Header" Path="ActualWidth"/>
<Binding Path="ActualWidth" RelativeSource="{RelativeSource Self}"/>
<Binding Path="ActualHeight" RelativeSource="{RelativeSource Self}"/>
</MultiBinding>
</Border.OpacityMask>
<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="3">
<Border BorderBrush="White" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="2"/>
</Border>
</Border>
<StackPanel Grid.ColumnSpan="2" Grid.Column="1" Grid.Row="0" Grid.RowSpan="3" Orientation="Horizontal" VerticalAlignment="Top" HorizontalAlignment="Right" >
<Button Margin="2" Content="Suchen"/>
<Button Margin="2" Content="Neu"/>
</StackPanel>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Page.Resources>
<Grid>
<Grid>
<GroupBox Header="Title" Style="{StaticResource GroupBoxStyle1}"></GroupBox>
</Grid>
</Grid>
2
的東西,我需要同樣的事情,在這裏找到了答案: http://wpf.2000things.com/2013/06/05/835-displaying-custom-content-in-a-groupbox-header/
不知道的.NET
哪個版本相關問題
- 1. WPF - 無法對齊GROUPBOX頭向右
- 2. WPF Groupbox標題位置對齊
- 3. WPF GroupBox標題對齊問題
- 4. Wpf對齊按鈕
- 5. 對齊按鈕內的文本/圖標
- 6. 對齊Qt GroupBox標籤
- 7. 對齊文本框和按鈕,引導
- 8. 對齊文本框和按鈕
- 9. 垂直對齊文本和按鈕
- 10. CardView按鈕和文本對齊不
- 11. HTML - 對齊單選按鈕和文本
- 12. 將按鈕,文本和Div對齊
- 13. WPF對齊網格中的文本框和按鈕?
- 14. 面板控制中的對齊按鈕
- 15. 對齊對象和按鈕
- 16. 如何將控件與WPF中的單選按鈕的文本對齊
- 17. 如何在XMADL中編寫文本和按鈕控件時對齊文本?
- 18. 右對齊ToolBarPanel控件WPF
- 19. WPF控件不對齊
- 20. 如何對齊WPF擴展控件切換按鈕
- 21. 對齊標籤與按鈕
- 22. 圖標和文本對齊
- 23. swift:標籤和按鈕文本的中心對齊方式
- 24. 文本對齊設計和圖標的按鈕用CSS
- 25. 引導按鈕中的文本和圖標的垂直對齊
- 26. 在WPF按鈕中將兩段文本可分離地對齊
- 27. 在運行時在一個wpf按鈕中左對齊文本
- 28. 按鈕對齊
- 29. 對齊按鈕
- 30. 如何對齊文本在TEXT按鈕