简体   繁体   English

来自 MarkupExtension SelectedItem 的 ComboBox ItemsSource 不同步

[英]ComboBox ItemsSource from MarkupExtension SelectedItem out of sync

I am struggling with the following.我正在努力解决以下问题。

I want to set a ComboBox 's ItemsSource with a object collection provided from a MarkupExtension .我想使用从MarkupExtension提供的对象集合设置ComboBoxItemsSource

Such as: ItemsSource="{ex:ItemsSource ModelType=m:Category}" where ItemsSource is a class ItemsSourceExtension deriving from MarkupExtension .例如: ItemsSource="{ex:ItemsSource ModelType=m:Category}"其中ItemsSource是从MarkupExtension派生的类ItemsSourceExtension

Problem is that when doing so, the ComboBox 's SelectedItem is null although its binding source has a value.问题是这样做时, ComboBoxSelectedItem为空,尽管它的绑定源有一个值。

组合框选定项为空 组合框选定项为空 I have tried a lot.我已经尝试了很多。 Have tried deriving from MarkupExtension and also tried subclassing Binding to no avail.尝试从MarkupExtension派生,也尝试子类化 Binding 无济于事。

I want to simulate the use of a standard Binding, where it works fine.我想模拟标准绑定的使用,它可以正常工作。

Such as: ItemsSource="{Binding DataContext.Categories, RelativeSource={RelativeSource AncestorType=v:DetailView}}"如: ItemsSource="{Binding DataContext.Categories, RelativeSource={RelativeSource AncestorType=v:DetailView}}"

Result:结果: 这是应该的

Finally figured it out.终于想通了。 The ItemsSource object collection provided by the MarkupExtension were originating from different EntityFramework DbContext instances. MarkupExtension提供的ItemsSource对象集合源自不同的EntityFramework DbContext实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM