• WPF Demo4


    <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>
    

      

    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();
            }
        }
    }
    

      

    <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 附加属性,也没有空白单元格。

  • 相关阅读:
    让 ijkplayer 支持兼容armv7 armv7s
    以太网私网建立:同一台电脑,不同电脑运行多个节点。
    solidity 语言总结笔记
    web.js 方法详解
    Fabric 环境搭建
    浅谈区块链1
    以太坊私链建立和geth的使用
    搭建联盟链
    fabric 网络 合约部署 和 测试
    【Advanced Windows Phone Programming】番外篇 WP8与WP7
  • 原文地址:https://www.cnblogs.com/YYkun/p/6866568.html
Copyright © 2020-2023  润新知