开发者

I've got a ComboBox that's giving me grief in WPF using the MVVM pattern

Here's my code:

<ComboBox Grid.Column="1" Grid.Row="9" ItemsSource="{Binding Path=PriorityEntries}" SelectedItem="{Binding Path=Priority,Mode=TwoWay}"/>

The comboBox is bound properly with PriorityEntries, and when i change the value of the comboBox the "set" of the bound property(Priority) is called setting it to what开发者_如何学Go it needs to be. However, when i close the UserControl that this combobox resides, it calls the set property again with a value of null and then sets what the selectedItem was to null. Why is the comboBox being bound again when I close the usercontrol. I tried setting the mode to OneTime, but that won't reflect any changes...


You can try 'capturing' the Priority value in a property in your ViewModel before the control closes and use the captured value. You could also modify the setter for Priority so that it doesn't allow it to be set once the control associated with the ViewModel has been closed.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜