【问题标题】:Is it possible to bind to Windows.Storage.ApplicationData.Current.LocalSettings.Values?是否可以绑定到 Windows.Storage.ApplicationData.Current.LocalSettings.Values?
【发布时间】:2012-11-11 15:17:17
【问题描述】:

我有一个控件,我希望将其映射到Windows.Storage.ApplicationData.Current.LocalSettings.Values["MyValue"]。

我可以直接绑定到这个变量还是需要添加一个视图模型?

【问题讨论】:

    标签: wpf windows-phone-8


    【解决方案1】:

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

    因此,只需将视图模型分配给您的页面,并在属性中公开值:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-06
      • 2013-01-30
      • 2011-09-30
      • 1970-01-01
      • 1970-01-01
      • 2017-06-01
      相关资源
      最近更新 更多