GroupBox
表示一个控件,该控件用于创建具有用户界面 (UI) 内容边框和标题的容器。
下图是一个的示例 GroupBox ,它包含一个 TabControl 和一个括在 StackPanel 中的 Button 。
名称 | 备注 | 权限 |
---|---|---|
当按下 GroupBox 的 AccessKey 时响应。 | protected | |
创建 AutomationPeer 控件的 GroupBox 的实现。 | protected |
GroupBox经常与RadioButton一起使用。
GroupBox相对于HeaderedContentControl无新增功能。
GroupItem
显示为组生成的可视子树的根。
GroupItem是 ContentControl ,这意味着它可以包含任何类型的单个对象 (例如字符串、图像或面板) 。 有关更多信息,请参见 ContentControl 类。
此控件的依赖属性可能由控件的默认样式设置。 如果按默认样式设置属性,则当控件出现在应用程序中时,属性可能会更改为默认值。 默认样式取决于应用程序运行时使用的桌面主题。 有关详细信息,请参阅 默认的 WPF 主题。
方法
名词 | 备注 | 权限 |
---|---|---|
ArrangeOverride | 排列 GroupItem 的内容 | protected |
OnApplyTemplate | 在应用新模板时生成 GroupItem 的可视化树 | public |
OnCreateAutomationPeer | 创建并返回此 AutomationPeer 的 GroupItem 对象 | protected |
接口
名词 | 备注 |
---|---|
IContainItemStorage.Clear | 清除所有的属性关联 |
IContainItemStorage.ClearItemValue | 删除指定的项目与该元素之间的关联 |
IContainItemStorage.ClearValue | 从所有属性列表中删除指定属性 |
IContainItemStorage.ReadItemValue | 返回与指定项相关的指定属性的值 |
IContainItemStorage.StoreItemValue | 存储指定的属性和值,并将它们与指定的项相关联 |
IHierarchicalVirtualizationAndScrollInfo.Constraints | 获取或设置表示控件视区和缓存的大小的对象 |
IHierarchicalVirtualizationAndScrollInfo.HeaderDesiredSizes | 获取表示控件标头所需大小的对象 |
IHierarchicalVirtualizationAndScrollInfo.InBackgroundLayout | 获取指示控件的布局传递是否出现在较低优先级中的值 |
IHierarchicalVirtualizationAndScrollInfo.ItemDesiredSizes | 获取或设置表示控件项的所需大小的对象 |
IHierarchicalVirtualizationAndScrollInfo.ItemsHost | 获取显示控件的项的 Panel |
IHierarchicalVirtualizationAndScrollInfo.MustDisableVirtualization | 获取或设置一个值,该值指示所属 ItemsControl 是否应虚拟化 |
XAML代码:
<Window x:Class="GroupBoxDemo.MainWindow"
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"
xmlns:local="clr-namespace:GroupBoxDemo"
mc:Ignorable="d"
Title="MainWindow" Height="250" Width="450">
<GroupBox Header="GroupBoxDemo">
<StackPanel>
<RadioButton Content="RadioButton1"/>
<RadioButton Content="RadioButton2"/>
</StackPanel>
</GroupBox>
</Window>
C#代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace GroupBoxDemo
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
GroupBox group = new GroupBox();
StackPanel stackPanel = new StackPanel();
RadioButton RadioButton1 = new RadioButton();
RadioButton RadioButton2 = new RadioButton();
RadioButton1.Content = "RadioButton1";
RadioButton2.Content = "RadioButton2";
stackPanel.Children.Add(RadioButton1);
stackPanel.Children.Add(RadioButton2);
group.Header = "GroupBoxDemo";
group.Content = stackPanel;
this.Content = group;
}
}
}