So right now I'm using a property on my control that binds to a bool property on my viewmodel called searcheditemfound (with its pair, searcheditemnotfound). I can't have just one property because even if I raise OnPropertyChanged("variableName), it will not activate the trigger unless there was an actual value change. This means that in the code for the view model, I have to do this really ugly looking:
SearchedItemNotFound = false; SearchedItemNotFound = true;
private bool _SearchedItemNotFound;
public bool SearchedItemNotFound
{
get
{
return _SearchedItemNotFound;
}
set
{
if (value != _SearchedItemNotFound)
{
_SearchedItemNotFound = value;
OnPropertyChanged("SearchedItemNotFound");
}
}
}
when what I would really like is to just tie to an event in the view model. However, eventtriggers only trigger off routed events. Can I place routed events in the viewmodel? I think I have to inherit from control to do that.
One post here: How can I Have a WPF EventTrigger on a View trigger when the underlying Viewmodel dictates it should?
mentioned using
<i:Interaction.Triggers>
<samples:DataEventTrigger EventName="YourEvent">
<im:ControlStoryboardAction Storyboard="{StaticResource Storyboard1}"
ControlStoryboardOption="Play"/>
</samples:DataEventTrigger>
</i:Interaction.Triggers>
which looks perfect, except that it requires expression blend and I'm in visual studio 2008 where it isn't available. I'm wondering what other options I have. I don't even mind if it's not MVVM. I'm not a purist, I'm just trying to understand what my options are.
Here
I wrote an answer, which refers to the use of events inViewModel
. – Anatoliy Nikolaev