1

I have a control with a value that I would like to be mapped to Windows.Storage.ApplicationData.Current.LocalSettings.Values["MyValue"].

Can I bind to this variable directly or do I need to add a viewmodel?

l33t
  • 18,692
  • 16
  • 103
  • 180

1 Answers1

2

To do that, you would need the x:Static markup extension, which unfortunately is unavailable on Windows Phone.

So, just assign a viewmodel to your page, and expose the value in a property:

public string MyValue
{
    get
    {
        return Windows.Storage.ApplicationData.Current.LocalSettings.Values["MyValue"];
    }
}

Or you can expose the whole dictionary:

public Windows.Storage.ApplicationDataContainer Settings
{
    get
    {
        return Windows.Storage.ApplicationData.Current.LocalSettings;
    }
}

Then bind it from the XAML:

<TextBlock Text="{Binding Path=Settings[MyValue]}" />
Community
  • 1
  • 1
Kevin Gosse
  • 38,392
  • 3
  • 78
  • 94