我在基类(视图模型)中有一个属性,当在XAML中的数据绑定中使用时,它不显示。但是,当我将该属性移动到派生视图模型时,它会显示出来。为什么呢?
XAML:
<TextBlock Margin="5,0,0,0" VerticalAlignment="Center"
Text="{Binding Path=ResxMessages.SelectPathToDevice}" />
代码背后:
public abstract class BaseViewModel{
protected bool ThrowOnInvalidPropertyName { get; set; }
/*Putting this property here doesn't work*/
private static Messages _resxMessages = null;
public static Messages ResxMessages
{
get
{
if (_resxMessages == null)
_resxMessages = new Messages();
return _resxMessages;
}
}
}
public class MainViewModel :BaseViewModel{
protected bool ThrowOnInvalidPropertyName { get; set; }
/*Putting this property here DOES work*/
private static Messages _resxMessages = null;
public static Messages ResxMessages
{
get
{
if (_resxMessages == null)
_resxMessages = new Messages();
return _resxMessages;
}
}
}