Jasoon 大神问,如何绑定静态属性。

我们经常有静态属性,那么我们如何绑定

假如我们的ViewModel有一个静态属性

        public static string CVTE
{
set;
get;
} = "lindexi";


一个方法是在xaml.cs写一个属性,get为静态属性。

public  string Property => ViewModel.ViewModel.CVTE;


在xaml绑定xaml.cs属性

      <TextBlock Text="{x:Bind Property,Mode=OneWay}"></TextBlock>


下面方法我没测试成功,但是有大神说他这样做是可以。

在需要绑定的类上写​​[Bindable]​

这样写的具体参见:​​http://www.jaylee.org/post/2012/03/07/Xaml-integration-with-WinRT-and-the-IXamlMetadataProvider-interface.aspx​

我不知道为何这样,知道的大神可以告诉我不?

然后在xaml写

xmlns:view="using:Bproperty.ViewModel"

<TextBlock Text="{x:Bind Path=(view:ViewModel.CVTE) }"
HorizontalAlignment="Center" VerticalAlignment="Center"/>