WPF中,X:Name和Name有什么区别呢?哪些时候该用哪个呢?
比如SolidColorBrush、Double只能写X:Name,不能写Name
请指教,谢谢WPF

解决方案 »

  1.   

    refer : http://www.cnblogs.com/tianyutingxy/archive/2011/02/23/1962078.html
      

  2.   

    我之前也纠结于这个问题。
    看的越多我就越糊涂。
    后面我总结成一句话。
    即:对象中没有Name成员的即可以用x:name代替

            <Button Name="huitest" Content="李四">
                <Button.Background>
                    <SolidColorBrush Color="AliceBlue" x:Name="huitest2" />
                </Button.Background>
          </Button>
    SolidColorBrush是没有Name这个成员。
    那么如果我们想在代码中调用它怎么办呢?
    加上x:Name="huitest2"即可。
    在后台代码中即可这样调用这个SolidColorBrush对象:
    huitest2.Color=Colors.Red;我的理解是 x:name可以帮助我们调用那些没有Name属性的对象。
      

  3.   

    XML也有命名空间的概念。就好比System.String和String有什么区别一样。
      

  4.   

    难道你用wpf才发现命名空间,用asp.net都没有发现?比如<asp:button>,这里也用到了命名空间。
      

  5.   

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"你看一般在XAML最开始都会声明这两个命名空间。所以问题其实很简单,控件属于前者的不用加x,属于后者的则必须加x。
      

  6.   

    x代表引用命名空间:"http://schemas.microsoft.com/winfx/2006/xaml"这一点我是知道的,不用多讲
      

  7.   

    据说没啥区别啊。。Name的作用其实就是x:Name