• 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之家
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    声明以及字符表述类--字母大小写的敏感性
    条款52:写了placement new 也要写placement delete(write placement delete if you write placement new)
    verdi知识点
    关于$test$plusargs和$value$plusargs的小结
    条款40:明智而审慎地使用多重继承(use multiple inheritance judiciously)
    条款39:明智而审慎地使用private继承(use private inheritance judiciously)
    条款38:通过复合塑模has-a或“根据某物实现出”
    条款37:绝不重新定义继承而来的缺省参数值(Never redefine a function's inherited default parameter value)
    自学nodejs系列
    五个典型的JavaScript面试题
  • 原文地址:https://www.cnblogs.com/wpf123/p/2052945.html
Copyright © 2020-2023  润新知