zoukankan      html  css  js  c++  java
  • WPF 学习笔记(十一)

    (1)子窗口界面设置

    <Window x:Class="WpfApplication1.InputWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="输入窗口" Height="101" Width="294" ResizeMode="NoResize" WindowStartupLocation="CenterScreen">
        <Grid>
            <Button Content="确定" Height="23" HorizontalAlignment="Right" Margin="0,35,8,0" Name="btnOk" VerticalAlignment="Top" Width="75" Click="btnOk_Click" />
            <Button Content="取消" Height="23" HorizontalAlignment="Left" Margin="114,35,0,0" Name="btnCancel" VerticalAlignment="Top" Width="75" Click="btnCancel_Click" />
            <TextBox Height="32" HorizontalAlignment="Left" Name="txtUserName" VerticalAlignment="Top" Width="278" />
        </Grid>
    </Window>

    (2)子窗口属性设置

    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 WpfApplication1
    {
        /// <summary>
        /// InputWindow.xaml 的交互逻辑
        /// </summary>
        public partial class InputWindow : Window
        {
            public string InputValue { set; get; }
            public InputWindow()
            {
                InitializeComponent();
            }
    
            private void btnCancel_Click(object sender, RoutedEventArgs e)
            {            
                DialogResult = false; //如果窗口是用ShowDialog打开的,则给dialogresult赋值就会自动关闭窗口,并把结果值返回
            }
    
            private void btnOk_Click(object sender, RoutedEventArgs e)
            {
                InputValue = txtUserName.Text;
                DialogResult = true; //如果窗口是用ShowDialog打开的,则给dialogresult赋值就会自动关闭窗口,并把结果值返回
            }
        }
    }

    (3)主界面设计

    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.Navigation;
    using System.Windows.Shapes;
    
    namespace WpfApplication1
    {
        /// <summary>
        /// MainWindow.xaml 的交互逻辑
        /// </summary>
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
            }
    
            private void btnOpen_Click(object sender, RoutedEventArgs e)
            {
                InputWindow inputWin = new InputWindow();
                bool? b = inputWin.ShowDialog();
    
                if (b == null)
                {
                    MessageBox.Show("没设置?");
                }else if(b == true){
                    MessageBox.Show("确定"+inputWin.txtUserName);
                }else{
                    MessageBox.Show("取消");
                }
            }
        }
    }
  • 相关阅读:
    Oracle创建表、修改表、删除表、约束条件语法
    Oracle中字符串截取常用方法总结
    Oracle 触发器(一)
    Oracle 触发器(二)
    Ajax-01
    Entity Framework-04
    Entity Framework-03
    Entity Framework-02
    Entity Framework-01
    DML、DCL、DDL
  • 原文地址:https://www.cnblogs.com/dLong/p/9581692.html
Copyright © 2011-2022 走看看