<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();
}
}
}