简体   繁体   中英

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 .

Such as: ItemsSource="{ex:ItemsSource ModelType=m:Category}" where ItemsSource is a class ItemsSourceExtension deriving from MarkupExtension .

Problem is that when doing so, the ComboBox 's SelectedItem is null although its binding source has a value.

组合框选定项为空 组合框选定项为空 I have tried a lot. Have tried deriving from MarkupExtension and also tried subclassing Binding to no avail.

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

Result: 这是应该的

Finally figured it out. The ItemsSource object collection provided by the MarkupExtension were originating from different EntityFramework DbContext instances.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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