是否可以绑定到Windows.Storage.ApplicationData.Current.LocalSettings.Values?

时间:2012-11-11 15:17:17

标签: wpf windows-phone-8

我有一个控件,其值我想映射到Windows.Storage.ApplicationData.Current.LocalSettings.Values["MyValue"]

我可以直接绑定到此变量,还是需要添加viewmodel?

1 个答案:

答案 0 :(得分:2)

为此,您需要x:Static标记扩展程序,不幸的是is unavailable on Windows Phone

因此,只需将viewmodel分配给您的页面,并在属性中公开该值:

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

或者你可以公开整个字典:

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

然后从XAML绑定它:

<TextBlock Text="{Binding Path=Settings[MyValue]}" />