title

author

date

CreateTime

categories

win10 uwp 绑定静态属性

lindexi

2018-2-13 17:23:3 +0800

2018-2-13 17:23:3 +0800

Win10 UWP

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]​

 ​

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

然后在xaml写

xmlns:view="using:Bproperty.ViewModel"

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