[英]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
提供的对象集合设置ComboBox
的ItemsSource
。
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.问题是这样做时,
ComboBox
的SelectedItem
为空,尽管它的绑定源有一个值。
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}}"
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.