交互触发器和通用属性?
我创建了一个 TriggerBase
类,名称为 CollectionContainsValueTrigger
。顾名思义,只要触发器包含特定值,就会调用该操作。
但是,我想创建触发器,以便它以接受 T
的各种 ObservableCollection
的方式运行,而不仅仅是显式类型的 ObservableCollection
。我尝试了对象的 ObservableCollection
,但绑定不起作用,因为类型与我的 ViewModel
的显式类型 ObservableCollection
不同。
我该怎么做?
xaml 示例:
<i:Interaction.Triggers>
<mi:CollectionContainsValueTrigger Collection="{Binding SomeStronglyTypedViewModelCollection}" Value="Some Value">
<SomeAction />
</mi:CollectionContainsValueTrigger>
</i:Interaction.Triggers>
I've created a TriggerBase
class, name CollectionContainsValueTrigger
. As its name suggests, the trigger invokes the action whenever it contains a certain value.
However, I would like to create the trigger so it acts in such a way that it accepts all kinds of ObservableCollection
of T
, not just an explicit typed of ObservableCollection
. I tried ObservableCollection
of object but the binding doesn't work because the Type is different from my ViewModel
's explicitly typed ObservableCollection
.
How can I do this?
xaml example:
<i:Interaction.Triggers>
<mi:CollectionContainsValueTrigger Collection="{Binding SomeStronglyTypedViewModelCollection}" Value="Some Value">
<SomeAction />
</mi:CollectionContainsValueTrigger>
</i:Interaction.Triggers>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果没有看到一些你想要实现的目标的例子,就很难提出建议。
如果我正确理解您的非泛型类需要对不同类型的某些基于泛型的类(如 ObservableCollection)进行多态访问,
为了适应这一点,我将使用多态适配器:
It is hard to suggest without seeing some examples of what you are trying to acheive.
If i understand correctly your non-generic class needs polymorphic access to some generic-based classes (like ObservableCollection) of different types
To accomodate this I would use a polymorphic adapter:
好吧,我意识到 xaml 目前不支持泛型,仅在未来版本中支持。如果是的话,那就解决了我的问题......
ok i realized that xaml does not support Generics currently, only in the future version. if it does, it would have solved my problem....