我无法理解如下的东西。我的项目在Prism 4.1 Sliverlight 5中。我使用MVVM模式。 我有一个静态类,这样Silverlight 5,Prism 5.1 StaticResource使用不工作的静态类
{
public static class RegionNames
{
public static string AUTH_LOGIN_REGION = "AuthRegion";
public static string TAB_TEST_REGION = "TabRegion";
public static string USER_TAB_REGION="UserTabRegion";
}
}
我试图用这个类Shell.xmal像下面。
<Grid.Resources>
<inf:RegionNames x:Key="rName"></inf:RegionNames>
</Grid.Resources>
现在这个资源我文本块中使用
结果:无文字出现。
<TextBlock Text="{Binding Source={StaticResource rNamee}, Path=USER_TAB_REGION}" Margin="20"></TextBlock>
现在我改变了这一类象下面这样:
{
public class RegionNames : INotifyPropertyChanged
{
public static string AUTH_LOGIN_REGION = "AuthRegion";
public static string TAB_TEST_REGION = "TabRegion";
public static string USER_TAB_REGION="UserTabRegion";
public RegionNames() {
AuthReginName = "HOLY COW POW POW !!";
}
private string _authReginName;
public string AuthReginName {
get {
return _authReginName;
}
set {
_authReginName = value;
OnPropertyChanged("AuthReginName");
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
}
,并用它这样
<TextBlock Text="{Binding Source={StaticResource rNamee}, Path=AuthReginName}"></TextBlock>
结果:文本出现了
这一次它的工作。为什么?我的静态defied字符串值不会来? 与对象创建类&设置属性值是否有任何关系?
是的,我后来才意识到这一点。 – akirti
关于x:Static它在Silverlight 5中不会像这样工作,因为它是静态类。 – akirti