首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

WPF,这段代码啥意思?该怎么解决

2013-08-04 
WPF,这段代码啥意思?UserControl x:ClassWPFRoutedEvent.UserControl1xmlnshttp://schemas.microsof

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"/>是不是引用命名空间呢,是什么意思呢?
[解决办法]
UserControl是一个用户控件。
<local:UserControl1 x:Name="test1"/> 引用了这个用户控件。
[解决办法]
你新建个usercontrol不就知道了
[解决办法]

引用:
Quote: 引用:

UserControl是一个用户控件。
<local:UserControl1 x:Name="test1"/> 引用了这个用户控件。

指的是自定义的控件吗?


直接在右键项目,有个用户控件,点这个你就知道了。
[解决办法]
引用:
Quote: 引用:

UserControl是一个用户控件。
<local:UserControl1 x:Name="test1"/> 引用了这个用户控件。

指的是自定义的控件吗?
你代码是复制别人的?你看下你用户控件有没有这个就知道了
------解决方案--------------------


UserControl1中的USER是什么、英文差了点吧,USER是用户,自定义是Custom

热点排行