Converter for ComboBox to Silverlight 4

I am trying to select a ComboBox item to set a stored value from a database.

It saved “I” or “D” in the database, and the converter returns “Direct” or “Indirect”.

ComboBox has two ComboBoxItems with the values ​​"Direct" and "Indirect".

Here is the code that I thought would work:

<ComboBox Name="cbMode" 
SelectedValue="{Binding Context.mode, Converter={StaticResource ModeConverter}, Mode=TwoWay}" >
       <ComboBoxItem Content="Direct" />
       <ComboBoxItem Content="Indirect" />
</ComboBox>

I know that it returns "Indirect", but it is not selected.

When I try to change the selected item in combo, it does not work, because it cannot convert from ComboBoxItem to string, so I support this problem in both directions.

How do i try? Should I make SelectedIndex with a numeric converter?

Thanks in advance.

+3
source
3

, - ( , ).

:

<ComboBox Name="cbMode" 
SelectedIndex="{Binding Context.mode, Converter={StaticResource ModeConverter}, Mode=TwoWay}" >
       <ComboBoxItem Content="Direct" />
       <ComboBoxItem Content="Indirect" />
</ComboBox>

, 0, D 1, .

, , ; -).

0
0

I usually try to catch such problems at my DB access level. You are limited on the Dev DB application side. When you receive your data, I convert from I / D to indirect / direct. When you set your details, I would simply cancel it. Allows you to encode your application against what makes sense.

Some people call it Application Centric, and it made my life a lot easier.

0
source

All Articles