欢迎莅临 SUN WU GANG 的园子!!!

世上无难事,只畏有心人。有心之人,即立志之坚午也,志坚则不畏事之不成。

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  470 随笔 :: 0 文章 :: 22 评论 :: 30万 阅读
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<Window x:Class="Demo4.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:Demo4"
        Title="{x:Static local:MainWindow.TitleTest}" Height="500" Width="525">
    <!--窗体级别资源-->
    <Window.Resources>
        <Style x:Key="{x:Type Label}" TargetType="{x:Type Label}">
            <Setter Property="FontStyle" Value="Italic"/>
            <Setter Property="Foreground" Value="Red"/>
            <Setter Property="FontSize" Value="36"/>
        </Style>
    </Window.Resources>
    <Grid ShowGridLines="True" UseLayoutRounding="True">
        <!--定义行数-->
        <Grid.RowDefinitions>
            <RowDefinition Height="3*"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="30"/>
        </Grid.RowDefinitions>
        <!--定义列数-->
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <StackPanel>
            <Label Content="{x:Static local:MainWindow.ageTest}" />
            <!--样式取值原则-就近原则-->
            <Label  Content="{x:Static local:MainWindow.nameTest}" FontSize="16"/>
            <Border BorderBrush="#FFE35A76" BorderThickness="10" Height="100" Name="border1" Width="200" Background="#FFEFE5E5" CornerRadius="10" DataContext="{Binding}" >
                <Label  Content="{x:Static local:MainWindow.ageTest}" />
            </Border>
            
            <UniformGrid >
                <Button Content="Window1" Click="Button_Click"/>
                <Button Content="b"/>
                <Button Content="c"/>
                <Button Content="d"/>
            </UniformGrid>
        </StackPanel>
 
        <StatusBar  Name="statusBar1" Grid.Row="2" Grid.ColumnSpan="3">
            <StatusBarItem Content="Status Bar"/>
        </StatusBar>
    </Grid>
 
</Window>

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
using System.Windows;
 
namespace Demo4
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public static string nameTest = "name:kunkun";
        public static string ageTest = "age:27";
        public static string TitleTest = "Static用法学习";
 
        public MainWindow()
        {
            InitializeComponent();
        }
 
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Window1 w = new Window1();
            w.Topmost = true;
            w.ShowDialog();
        }
    }
}

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<Window x:Class="Demo4.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Window1" Height="300" Width="300">
    <Grid>
        <DockPanel LastChildFill="True">
            <Button DockPanel.Dock="Top" Content="Top"/>
            <Button DockPanel.Dock="Bottom" Content="Bottom"/>
            <Button DockPanel.Dock="Left" Content="Left"/>
            <Button DockPanel.Dock="Right" Content="Right"/>
            <Button  Content="Middle"/>
        </DockPanel>
    </Grid>
</Window>

运行效果如下:

注意:Grid的列宽与行高可采用固定、自动、按比列三种方式定义 。

UniformGrid 

UniformGrid 就是Grid的简化版,每个单元格的大小相同,不需要定义行列集合。

每个单元格始终具有相同的大小,每个单元格只能容纳一个控件,将自动按照定义在其内部的元素个数,自动创建行列,并通常保持相同的行列数。

UniformGrid 中没有Row 和Column 附加属性,也没有空白单元格。

posted on   sunwugang  阅读(272)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
点击右上角即可分享
微信分享提示