<UserControl x:Class="WPFRoutedEvent.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/up-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<StackPanel>
<Button x:Name="testButton" Content="testButton" Click="TestButton_Click" />
</StackPanel>
</Grid>
</UserControl>
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
private void TestButton_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show(string.Format("sender 类型:{0} \n\r source 类型:{1} \n\r originalSource 类型: {2}",
sender.GetType().Name, e.Source.GetType().Name, e.OriginalSource.GetType().Name), "子窗体消息");
}
}
<Window x:Class="WPFRoutedEvent.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525"
xmlns:local="clr-namespace:WPFRoutedEvent">
<Grid>
<local:UserControl1 x:Name="test1"/>
</Grid>
</Window> public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.AddHandler(Button.ClickEvent, new RoutedEventHandler((sender, e) =>
{
MessageBox.Show(string.Format("sender 类:{0} \n\r source 类型:{1} \n\r originalSource 类型 {2}",
sender.GetType().Name, e.Source.GetType().Name, e.OriginalSource.GetType().Name), "主窗体消息");
}));
}
}问题:
上面的UserControl那一段是什么东西哦?
下面的<local:UserControl1 x:Name="test1"/>是不是引用命名空间呢,是什么意思呢?
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/up-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<StackPanel>
<Button x:Name="testButton" Content="testButton" Click="TestButton_Click" />
</StackPanel>
</Grid>
</UserControl>
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
private void TestButton_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show(string.Format("sender 类型:{0} \n\r source 类型:{1} \n\r originalSource 类型: {2}",
sender.GetType().Name, e.Source.GetType().Name, e.OriginalSource.GetType().Name), "子窗体消息");
}
}
<Window x:Class="WPFRoutedEvent.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525"
xmlns:local="clr-namespace:WPFRoutedEvent">
<Grid>
<local:UserControl1 x:Name="test1"/>
</Grid>
</Window> public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.AddHandler(Button.ClickEvent, new RoutedEventHandler((sender, e) =>
{
MessageBox.Show(string.Format("sender 类:{0} \n\r source 类型:{1} \n\r originalSource 类型 {2}",
sender.GetType().Name, e.Source.GetType().Name, e.OriginalSource.GetType().Name), "主窗体消息");
}));
}
}问题:
上面的UserControl那一段是什么东西哦?
下面的<local:UserControl1 x:Name="test1"/>是不是引用命名空间呢,是什么意思呢?
<local:UserControl1 x:Name="test1"/> 引用了这个用户控件。