Setting DependencyProperty via EventTrigger
Posted: 20 Oct 2017, 08:30
Greetings fellow coders,
I need to set depProp (NsBool, ShowOverlayHelp) via a mouse click event (I cannot, due to my component not being a control, use an event such as MouseDown etc.). However, setting the binding seems not to work, the respective setter function in the view model never gets called. Any help appreciated.
Here the sample code for the Button element:
P.S.: I also tried using a togglebutton, binding ShowOverlayHelp to the IsChecked property and setting the latter in the mouse click event. Neither worked.
I need to set depProp (NsBool, ShowOverlayHelp) via a mouse click event (I cannot, due to my component not being a control, use an event such as MouseDown etc.). However, setting the binding seems not to work, the respective setter function in the view model never gets called. Any help appreciated.
Here the sample code for the Button element:
P.S.: I also tried using a togglebutton, binding ShowOverlayHelp to the IsChecked property and setting the latter in the mouse click event. Neither worked.
Code: Select all
<Button Visibility="Hidden" Grid.ZIndex="0"
Opacity="0.0" Background="Black" Grid.RowSpan="4" Grid.ColumnSpan="3">
<Button.Triggers>
<EventTrigger RoutedEvent="ToggleButton.Click">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<BooleanAnimationUsingKeyFrames Storyboard.TargetProperty="{Binding ShowOverlayHelp}" Duration="0">
<DiscreteBooleanKeyFrame KeyTime="0:0:0" Value="False"/>
</BooleanAnimationUsingKeyFrames>
<DoubleAnimation Storyboard.TargetProperty="Opacity" To="1.0" Duration="0:0:0.3"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Button.Triggers>
<Button.Style>
<Style>
<Style.Triggers>
<DataTrigger Binding="{Binding ShowHelpOverlay}" Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{x:Static Visibility.Visible}"/>
</ObjectAnimationUsingKeyFrames>
<DoubleAnimation Storyboard.TargetProperty="Opacity" To="0.6" Duration="0:0:0.3"/>
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
</DataTrigger>
<DataTrigger Binding="{Binding ShowHelpOverlay}" Value="False">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity" To="0.0" Duration="0:0:0.3"/>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0:0:0.3" Value="{x:Static Visibility.Hidden}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>