WPF 之1

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:WpfApplication1"
        Title="MainWindow" Width="500" Height="400">
    <Grid ShowGridLines="True" UseLayoutRounding ="True">
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="*" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition  />
            <ColumnDefinition/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <local:MyButton Content="cliked me" UserWindowType ="{x:Type TypeName=local:Mywindow}" x:Name ="btn1" x:FieldModifier ="public" Grid.Row="0" Grid.Column="0"  Grid.RowSpan="2" Click="btn_cliked" />
        <Button Content="cliked me" x:Name ="btn2" x:FieldModifier="protected" Grid.Row="0" Grid.Column="0" Click ="btn_cliked" Grid.ColumnSpan="2"  Background="Blue"  />
    </Grid>
  
</Window>
<Window x:Class="WpfApplication1.Mywindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Mywindow" Height="300" Width="300">
    <StackPanel Background="LightBlue" Orientation="Vertical">
        <TextBox Name="textBox1" Margin="5" />
        <TextBox  Name="textBox2" Margin="5" />
        <TextBox  Name="textBox3" Margin="5" />
        <Button Content="Button"  Margin="25" />
    </StackPanel>
</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.Navigation;
using System.Windows.Shapes;

namespace WpfApplication1
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void btn_cliked(object sender, RoutedEventArgs e)
        {
            Lista<int> ps = new Lista<int>();
            ps.a = 3;
            //Human h = (Human)this.FindResource("human");
            if (sender is MyButton)
            {
               ((MyButton)sender).Click();
            }
            else
            {
                MessageBox.Show(string.Format("{0:D}", ps.a));
            }
        }
    }
    public class Human
    {
        public string Name { set; get; }
        public Human Child { set; get; }
    }
    public class Lista<T>
    {
        public T a;
    }
    public class MyButton:Button
    {
        public Type UserWindowType
        {
            get;
            set;
        }
        public void  Click()
        {
            Window win = Activator.CreateInstance(this.UserWindowType) as Window;
            if (win != null)
            {
                win.ShowDialog();
            }
        }
        //protected override void OnClick()
        //{
        //    base.OnClick();
        //    Window win = Activator.CreateInstance(this.UserWindowType) as Window;
        //    if (win != null)
        //    {
        //        win.ShowDialog();
        //    }

        //}
    }
}
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>
    /// Mywindow.xaml 的交互逻辑
    /// </summary>
    public partial class Mywindow : Window
    {
        public Mywindow()
        {
            InitializeComponent();
        }
    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值