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;
      }
    }
}
Metro Smurf
  • 37,266
  • 20
  • 108
  • 140
abjbhat
  • 999
  • 3
  • 13
  • 24

1 Answers1

0

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

Check the following post will help you further: Binding to static property

Community
  • 1
  • 1
HCL
  • 36,053
  • 27
  • 163
  • 213