- AndreasEnscape
- Posts: 22
- Joined:
Setting DependencyProperty via EventTrigger
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>
- AndreasEnscape
- Posts: 22
- Joined:
Re: Setting DependencyProperty via EventTrigger
Well, I really need to know whether this is a bug. I tried the following using ordinary WPF and it works perfectly fine. With Noesis however, nothing happens:
Code: Select all
<Button DataContext="{Binding MyHelpDataContext}" Background="Black" >
<Button.Triggers>
<EventTrigger RoutedEvent="ToggleButton.Click">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<BooleanAnimationUsingKeyFrames Storyboard.Target"{Binding}" Storyboard.TargetProperty="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>
Last edited by AndreasEnscape on 24 Oct 2017, 07:56, edited 1 time in total.
- AndreasEnscape
- Posts: 22
- Joined:
Re: Setting DependencyProperty via EventTrigger
I solved using the button's command ability. However, would be nice to know if I should file a bug/missing feature report.
Regards,
Andy
Regards,
Andy
-
sfernandez
Site Admin
- Posts: 2984
- Joined:
Re: Setting DependencyProperty via EventTrigger
Hi,
You said your code was working fine in WPF, but I checked that Buttons with Visibility="Hidden" in WPF don't receive mouse events and don't generate clicks.
Did you change anything on the xaml attached to make it work?
For example, I was able to have this sample working fine by setting the Visibility="Visible" while still having the Opacity="0". It worked both in WPF and Noesis.
Anyway I noticed one thing that was wrong in Noesis, it turns out that VisualTreeHelper.HitTest() is not taking into account "Hidden" elements, but they are in WPF. Could you please report this as a bug in our bugtracker?
You said your code was working fine in WPF, but I checked that Buttons with Visibility="Hidden" in WPF don't receive mouse events and don't generate clicks.
Did you change anything on the xaml attached to make it work?
For example, I was able to have this sample working fine by setting the Visibility="Visible" while still having the Opacity="0". It worked both in WPF and Noesis.
Anyway I noticed one thing that was wrong in Noesis, it turns out that VisualTreeHelper.HitTest() is not taking into account "Hidden" elements, but they are in WPF. Could you please report this as a bug in our bugtracker?
- AndreasEnscape
- Posts: 22
- Joined:
Re: Setting DependencyProperty via EventTrigger
Greetings,
the hidden flag was an error, corrected it. The button is visible and I cannot get any DepProp set within the <EventTrigger>. I corrected the code example.
Best regards,
Andy
the hidden flag was an error, corrected it. The button is visible and I cannot get any DepProp set within the <EventTrigger>. I corrected the code example.
Best regards,
Andy
-
sfernandez
Site Admin
- Posts: 2984
- Joined:
Re: Setting DependencyProperty via EventTrigger
Could you please create a ticket in our bugtracker and attach the code of the DataContext (exposing the MyHelpDataContext) and the DependencyObject with the ShowOverlayHelp property.
This way I could try to reproduce your exact scenario.
This way I could try to reproduce your exact scenario.
- AndreasEnscape
- Posts: 22
- Joined:
Re: Setting DependencyProperty via EventTrigger
Will do next week!
Who is online
Users browsing this forum: No registered users and 94 guests