添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
1.Grid 控件介绍

Winform Groupbox 分组容器控件

Wpf GroupBox 分组 带标题 HeaderedContentControl 带标题的内容控件

只能有一个子元素作为它的内容 Content Header 边框

结合布局控件(容器)

分组显示

2.具体案例

<Window x:Class="WpfAppTest.GroupBoxWindow"
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:WpfAppTest"
mc:Ignorable="d"
Title="GroupBoxWindow" Height="450" Width="800" Loaded="Window_Loaded">
<Grid>
<!-- 分组控件 内容控件 只能有一个元素作为它的Content
如果我想在它的内部呈放多个子元素???? ——布局控件 -容纳多个元素
-->
<GroupBox Header="导航菜单" Width="200" Height="200" BorderThickness="2" BorderBrush="Red">
<StackPanel>
<Label Content="这是一个GroupBox控件"/>
<Label Content="这是一个GroupBox控件"/>
<Label Content="这是一个GroupBox控件"/>
<Label Content="这是一个GroupBox控件"/>
</StackPanel>
</GroupBox>
<GroupBox Header="导航菜单2" Width="221" Height="200" BorderThickness="2" BorderBrush="Red" Margin="32,110,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Name="gbInfo">
<StackPanel Orientation="Vertical" >
<StackPanel Orientation="Horizontal" >
<Label Content="用户名:"/>
<TextBox Name="txtUserName" Text="userName" Width="150"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,10,0,0">
<Label Content="密码:"/>
<PasswordBox Password="123456" Width="150"/>
</StackPanel>
</StackPanel>
</GroupBox>
</Grid>
</Window>
private void Window_Loaded(object sender, RoutedEventArgs e)
{
//如果我们没有设置TextBox的name属性,通过GroupBox控件去获取
StackPanel spFirst = gbInfo.Content as StackPanel;
foreach(var ele in spFirst.Children)
{
StackPanel sp = ele as StackPanel;
foreach(var ele2 in sp.Children)
{
if(ele2 is TextBox)
{
TextBox txt = ele2 as TextBox;
string name = txt.Text;
}
}
}

string name1 = txtUserName.Text;//直接通过name属性获取控件的Text
}