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("取消");
                }
            }
        }
    }
  • 相关阅读:
    一周精彩内容分享(第 5 期):货拉拉悲剧的背后
    关于 HTTP 后端人员需要了解的 20+ 图片!
    百度地图午夜暗蓝风格
    百度地图开发自定义信息窗口openInfoWindow样式
    百度地图infowindow上添加自定义点击事件
    js显示当前日期时间和星期几
    iview 树形异步加载,首次加载子节点不能选择,点击父节点后才可以选择
    js 修改属性名和值。并只保留需要的属性
    css 条形百分比
    echarts 3d饼图
  • 原文地址:https://www.cnblogs.com/dLong/p/9581692.html
Copyright © 2011-2022 走看看