l33t
l33t

Reputation: 19937

Is it possible to bind to Windows.Storage.ApplicationData.Current.LocalSettings.Values?

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?

Upvotes: 1

Views: 1160

Answers (1)

Kevin Gosse
Kevin Gosse

Reputation: 39007

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]}" />

Upvotes: 2

Related Questions