StaticResource指向的对象通常是Xaml里定义的Style或者Template之类。
x:static指向的对象通常是后台代码里的某个静态类。用来在Xaml中引用类的静态字段或静态属性,如Text={x:Static local:Window1.ShowText}。
原文出处:http://www.im47.cn/?p=482
ElementName
The ElementName property is used to reference an object by the name of the object. This is particularly useful in XAML, where you can directly reference other elements defined in XAML.
举例
<StackPanel Background=”Blue”>
<Button x:Name=”refButton” Background=”Orange”/>
<Button Background=”{Binding ElementName=refButton, Path=Background}”/>
</StackPanel>
Source
The Source property is used to specify an object reference on which the binding Path or XPath will be evaluated. The Source property is usually used when the object on which the Binding is set is known and differs from the DataContext.
举例:
<CustomClass1 Property1=”{Binding Source={x:Static DateTime.Now}, Path=Day}”/>
<CustomClass1 Property1=”{Binding Source={StaticResource AnotherElement}, Path=ActualWidth}”/>
简单地说,“ElementName”用于绑定到xaml界面设计中添加的其它控件对象,“Source”用于绑到资源中的对象。
————————————————
版权声明:本文为CSDN博主「Metal1」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/Metal1/article/details/41944697
X:Static是一个常用的标记扩展,它的功能是在XAML文档中使用数据类型的static成员。因为XAML中是不能编写逻辑代码的,所以使用x:Static访问static成员一定是数据类型的属性或字段。
下面是实例:
首先在Window里面添加两个成员,一个是static字段,一个是static属性。
public partial class Windows : Window
{
public static string Titles = "Hello";
public static string text { get { return "World"; } }
public Windows()
{
InitializeComponent();
}
}
然后在XAML中使用x:Static来访问这两个成员:
<Window x:Class="WpfApplication1.Key"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApplication1"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
mc:Ignorable="d"
Title="{x:Static local:Key.Titles}" Height="300" Width="300">
<StackPanel>
<TextBlock FontSize="20" Text="{x:Static local:Key.text}"/>
</StackPanel>
</Window>
————————————————
版权声明:本文为CSDN博主「 认」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_44552202/article/details/93967376