2010-08-15 46 views
1

我在基类(视图模型)中有一个属性,它在XAML中用于数据绑定时未显示。但是,当我将该属性移动到派生视图模型时,它会显示出来。为什么?无法在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; 
     } 
    } 
} 

回答

0

或许真的是因为他们被声明static(这是你的意图或者只是不期而遇)?

检查以下职位将帮助您进一步:Binding to static property

+0

Yep..that的吧。必须一直尝试不同的东西,并将其留在。谢谢! – abjbhat 2010-08-15 17:58:06