What is the XAML equivalent for binding SelectedIndexProperty in .cs .net silverlight code?
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" F开发者_开发百科oreground="#FFD41D1D" Height="25" VerticalAlignment="Top">
How do I express the same thing in XAML?
Thanks!
-Ray
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}" />
精彩评论