Binding ComboBox.SelectedItem in Silverlight

前端 未结 2 1175
死守一世寂寞
死守一世寂寞 2020-12-19 13:38

This one is driving me crazy. Here\'s the XAML:

    

        
相关标签:
2条回答
  • 2020-12-19 13:44

    Of course the binding has to be TwoWay. But setting a ItemsSource to a control doesn't means that the DataContext (where SelectedItem variable should point to) is set. Ensure that combo's DataContext is well set. (in my case, to Page. As selectedStuff is a Page property.

    cmbStuff.DataContext = Me '(from  Page.Load)
    
    0 讨论(0)
  • 2020-12-19 13:46

    Try this:

     <ComboBox ItemsSource="{Binding Path=Thing.Stuff}"                
          SelectedItem="{Binding Path=Thing.SelectedStuff, Mode=TwoWay}">
    

    SelectedItem does not like to be bound OneWay. I haven't had a chance to try it out in Silverlight 2 but in Silverlight 3 you will even get the yellow triangle of death if you don't use TwoWay binding.

    0 讨论(0)
提交回复
热议问题