zoukankan      html  css  js  c++  java
  • WPF之DockPanel 、 StackPanel

    <Window x:Class="WPFdemo1.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Window1" Height="327" Width="729">
        <DockPanel Name="dockPanel1" LastChildFill="False">
            <Button Name="button1" DockPanel.Dock="Top">1</Button>
            <Button Name="button2" DockPanel.Dock="Bottom" >2</Button>
            <Button Name="button3" DockPanel.Dock="Left">3</Button>
            <Button Name="button4" DockPanel.Dock="Right">4</Button>
            <Button DockPanel.Dock="Top">剩余空间</Button>
        </DockPanel>
    </Window>

    <Window x:Class="WPFdemo1.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="简单对话框实例" Height="327" Width="729">
        <DockPanel Name="dockPanel1">
            <StackPanel Name="stackPanel1" Orientation="Horizontal" DockPanel.Dock="Bottom" HorizontalAlignment="Right">
                <Button Name="button1" Margin="10,10,2,10" Padding="3">确定</Button>
                <Button Name="button2" Margin="2,10,10,10" Padding="3">返回</Button>
            </StackPanel>
            <TextBlock Name="textBlock1" Text="简单对话框实例,按请单击确定返回" Margin="10" />
        </DockPanel>
    </Window>

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    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.Shapes;

    namespace WPFdemo1
    {
        /// <summary>
        /// Window3.xaml 的交互逻辑
        /// </summary>
        public partial class Window3 : Window
        {
            public Window3()
            {
                InitializeComponent();
                this.Content = CreateGrid();
            }

            public Grid CreateGrid()
            {
                Grid grd = new Grid();
                RowDefinition row1 = new RowDefinition();
                row1.Height = new GridLength(1, GridUnitType.Star);
                grd.RowDefinitions.Add(row1);
                RowDefinition row2 = new RowDefinition();
                row2.Height = GridLength.Auto;
                grd.RowDefinitions.Add(row2);
                TextBox txt = new TextBox();
                txt.Text = "c测试";
                txt.TextWrapping = TextWrapping.Wrap;
                Grid.SetRow(txt, 0);
                Grid.SetColumn(txt, 0);
                grd.Children.Add(txt);

                StackPanel stk = new StackPanel();
                stk.Orientation = Orientation.Horizontal;
                stk.HorizontalAlignment = HorizontalAlignment.Right;
                Grid.SetColumn(stk, 0);
                Grid.SetRow(stk, 1);
                grd.Children.Add(stk);


                Button btn = new Button();
                btn.Margin = new Thickness(10, 10, 2, 10);
                btn.Content = "确定";
                btn.Padding = new Thickness(3);
                stk.Children.Add(btn);

                Button btn1 = new Button();
                btn1.Margin = new Thickness(2, 10, 10, 10);
                btn1.Content = "取消";
                btn1.Padding = new Thickness(3);
                stk.Children.Add(btn1);
                return grd;


            }

            private void Window_Loaded(object sender, RoutedEventArgs e)
            {

            }
        }
    }

    作者:wpf之家
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    CentOS 7 将 python版本升级为3.x后产生的各种问题
    CentOS 7.0 Firewall防火墙配置
    CentOS7.2+Python3x+Flask部署标准化配置流程
    CentOS 7 下安装 Nginx
    CentOS7下安装python-pip
    CentOS 7 安装字体
    centos中文目录换成英文目录
    搭建typecho个人博客和主题优化
    迭代器与生成器
    装饰器函数
  • 原文地址:https://www.cnblogs.com/wpf123/p/2052945.html
Copyright © 2011-2022 走看看