views:

22

answers:

1

I’ve got a property in a base class (view model), which when used in data binding in XAML doesn’t show up. It does however show up when I move that property to the derived view model. Why?

XAML:

<TextBlock  Margin="5,0,0,0" VerticalAlignment="Center" 
  Text="{Binding Path=ResxMessages.SelectPathToDevice}" />

Code Behind:

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;
      }
    }
}
A: 

Maybe something because they are declared static (is this your intention or just accidentaly)?

Check the following post will help you further: http://stackoverflow.com/questions/936304/problem-binding-to-static-property

HCL
Yep..that's it. Must've been trying different things and left that in. Thanks!
abjbhat