WPF基础五:UI③带标题内容控件GroupBox

GroupBox

表示一个控件,该控件用于创建具有用户界面 (UI) 内容边框和标题的容器。

下图是一个的示例 GroupBox ,它包含一个 TabControl 和一个括在 StackPanel 中的 Button 。

GroupBoxImage

名称备注权限

OnAccessKey

当按下 GroupBox 的 AccessKey 时响应。protected

OnCreateAutomationPeer

创建 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;
        }
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值