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("取消");
                }
            }
        }
    }
  • 相关阅读:
    node 中的 异步地狱回调
    node 同步和异步的概念
    【Node】File System
    阅读《软技能:代码之外的生存指南》读书笔记
    整理前端学习资料以便日后查看
    【css】单选框和复选框文字垂直居中问题
    [CSS]图片与文字对齐问题--摘自张鑫旭博客
    百度首页换一换功能js实现
    个人加分项
    开课第十五周周总结
  • 原文地址:https://www.cnblogs.com/dLong/p/9581692.html
Copyright © 2011-2022 走看看