0

这是我的 xaml:

SelectedItem="{Binding Source={StaticResource Settings}, Path=Default.Selected, Converter={StaticResource SelectedTabConverter}}"

我在 Convert() 和 ConvertBack() 中添加了 Console.WriteLine(),所以我可以看到他们正在做他们应该做的事情。但是,当我在将设置保存到 OnExit() 之前检查我的设置时,我看到设置没有更改。我认为这个绑定是双向的,我对 UI 所做的任何更改都应该同时更改设置。任何想法?

4

1 回答 1

2

首先,如果不阅读您之前的问题,很难说出您的问题是什么。

您已在 App 的 ResourceDictionary 中创建了一个 Settings 对象作为资源。没有必要这样做。只需绑定到Settings.Default如下所示的静态对象(并在您的其他问题的答案中正确显示)。

{Binding Path=Selected, Source={x:Static properties:Settings.Default}}

XML 命名空间properties引用Properties应用程序的命名空间。

<Window ...
        xmlns:properties="clr-namespace:MyHomework__MVVM_.Properties"
        ... >

除此之外,您应该绑定到SelectedIndex属性而不是 SelectedItem。这样你就不需要转换器了。

SelectedIndex="{Binding Path=Selected, Source={x:Static properties:Settings.Default}}"

另请参阅此问题

于 2013-01-21T08:45:33.007 回答