0

This is my xaml:

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

I added Console.WriteLine() in Convert() and ConvertBack() so I could see that they were doing what they were supposed to do. However, when I checked my setting before saving it in my OnExit(), I saw that the setting was not changed. I thought this binding was two-way and I changed anything to the UI should change the setting at the same time. Any idea?

user1447343
  • 1,417
  • 4
  • 18
  • 24

1 Answers1

2

First, it's hard to tell what your problem is without reading your previous question.

You have created a Settings object as a resource in your App's ResourceDictionary. There's no need to do that. Just bind to the static Settings.Default object like shown below (and correctly shown in the answer to your other question).

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

where the XML namespace properties references the Properties namespace of your application.

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

Aside from that you should bind to the SelectedIndex property instead of SelectedItem. That way you would not need a converter at all.

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

See also this question.

Community
  • 1
  • 1
Clemens
  • 123,504
  • 12
  • 155
  • 268
  • Love to see people use `x:Static` in their XAML. – Nicolas Repiquet Jan 21 '13 at 08:54
  • I should have put "+1" first for it to be clearer :) For instance, I make all my converters singletons, and use `x:Static` to reference them instead of the usual `StaticResource` mess. – Nicolas Repiquet Jan 21 '13 at 09:14
  • Well, it wasn't my design to make `Settings.Default` a static property. It's just the standard way how setting are created in a WPF project and accessed in binding expressions. – Clemens Jan 21 '13 at 09:17
  • Thanks for clearing that up and thanks for the link. UpdateSourceTrigger is exactly what I needed to set to make this work...I have worked with it for a couple of times I can't believe it didn't come to me when I stumbled upon this problem. – user1447343 Jan 21 '13 at 15:47