I was trying to add some visual feed back for a list box that supports drag and drop. Seems like I should be able to add some setters to an EventSetter and be done. However, eventsetters don't support setters. Do I really have to make a storyboard to implement this behavior?
What is Microsoft's rational for this?
<Style TargetType="{x:Type ListBox}">
<Style.Triggers>
<EventTrigger RoutedEvent="DragEnter">
<!--WHy Can't i Add seters here? e.g.
<Setter Property="ForeColor" Value="Red">
-->
</EventTrigger>
</Style.Triggers>
</Style>
A setter doesn't just set a property in response to state changing, it also restores the property to its previous value when the state changes back. There's no "changes back" with event triggers, so using setters with them would be like pushing something onto a stack that never gets popped.
I think a much better question, under the circumstances, is "why isn't there an IsDragOver
property?"
You could, maybe, try something like this? This is sorta-pseudo code, I don't have VS here to test it, but it should work. Using reflector you should be able to reverse engineer SetterAction and have this Setter work almost exactly the same way, in theory.
<TextBox Text="ListBox" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="DragEnter" >
<behavior:SetterAction Property="ListBox.ForeColor" Value="Red"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBox>
public class SetterAction : TargetedTriggerAction<FrameworkElement>
{
public DependencyProperty Property { get; set; }
public Object Value { get; set; }
protected override void Invoke(object parameter)
{
AssociatedObject.SetValue(Property, Value);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With