开发者

What is the XAML equivalent for binding SelectedIndexProperty in .cs .net silverlight code?

开发者 https://www.devze.com 2022-12-18 22:57 出处:网络
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.

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}" />
0

精彩评论

暂无评论...
验证码 换一张
取 消