Interactivity Triggers and Generic properties?
I've created a TriggerBase
class, name CollectionContainsValueTrigger
. As its name su开发者_C百科ggests, 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>
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:
class ObservableCollectionAdapterBase
{
virtual void Method1(){}
virtual void Method2(){}
}
class ObservableCollectionAdapter<T, TCollectionType> : ObservableCollectionAdapterBase
where TCollectionType : IObservableCollection<T>
{
public ObservableCollectionAdapter(TCollectionType collection)
{
_collection = collection;
}
override void Method1(){ _collection.DoSomething(); }
override void Method2(){ _collection.DoSomething(); }
}
ok i realized that xaml does not support Generics currently, only in the future version. if it does, it would have solved my problem....
精彩评论