WPF,这段代码啥意思?
<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/markup-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/markup-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"/>是不是引用命名空间呢,是什么意思呢?
...全文
相关推荐
WPF全系列事例代码
WPF基础教程所有相关的源代码,博客文章请查阅:http://blog.csdn.net/fwj380891124 之WPF板块类容。非常详细的介绍了WPF,适合初学者入门学习。
WPF数据绑定实战代码详解
经过这一轮深度剖析,我们可以归纳出几条黄金法则:永远初始化 DataContextcsharp// 不要留空!合理使用 UpdateSourceTrigger + Delay文本输入尽量用LostFocus或带Delay的优先使用 MultiBinding 而非 ConverterParameter多参数逻辑更适合善用 FallbackValue 提升容错能力让应用在异常情况下依然可用大型项目务必统一管理 Converters创建专门的。
WPF优秀开源代码合集
WPF优秀开源代码合集
WPF打开图片文件放入image中
简单的浏览图片并放入image中。。新手合适~
WPF DataGrid ComboBox下拉框数据绑定 代码实例
这是我的博客 里提到的 表格使用的整个项目代码


