views:

16

answers:

1

I have been playing with bindings in silverlight, and have figured out how to bind in code, but would prefer to keep the binding in the XAML.

This is the code that works in my .cs file:

  System.Windows.Data.Binding IDBinding = new System.Windows.Data.Binding("ID");
            IDBinding.Source = MyTrans;
            IDBinding.Mode = System.Windows.Data.BindingMode.TwoWay;
            cbComboBox.SetBinding(ComboBox.SelectedIndexProperty, IDBinding);

this is my XAML line:

<ComboBox x:Name="cbComboBox"   Margin="4,20,6,0" Foreground="#FFD41D1D" Height="25" VerticalAlignment="Top">

How do I express the same thing in XAML?

Thanks!

-Ray

+1  A: 

Assuming that you set the DataContext of the parent control of the ComboBox (or on the combobox itself) to MyTrans, the following should do it:

<ComboBox x:Name="cbComboBox" SelectedIndex="{Binding ID, Mode=TwoWay}" />
Henrik Söderlund