Reputation: 19937
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
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