AndreasEnscape
Topic Author
Posts: 22
Joined: 01 Aug 2017, 07:37

Setting DependencyProperty via EventTrigger

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.
 <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
Topic Author
Posts: 22
Joined: 01 Aug 2017, 07:37

Re: Setting DependencyProperty via EventTrigger

23 Oct 2017, 08:58

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:
 <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
Topic Author
Posts: 22
Joined: 01 Aug 2017, 07:37

Re: Setting DependencyProperty via EventTrigger

23 Oct 2017, 10:29

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
 
User avatar
sfernandez
Site Admin
Posts: 1912
Joined: 22 Dec 2011, 19:20

Re: Setting DependencyProperty via EventTrigger

23 Oct 2017, 16:49

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?
 
AndreasEnscape
Topic Author
Posts: 22
Joined: 01 Aug 2017, 07:37

Re: Setting DependencyProperty via EventTrigger

24 Oct 2017, 07:56

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
 
User avatar
sfernandez
Site Admin
Posts: 1912
Joined: 22 Dec 2011, 19:20

Re: Setting DependencyProperty via EventTrigger

24 Oct 2017, 20:54

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.
 
AndreasEnscape
Topic Author
Posts: 22
Joined: 01 Aug 2017, 07:37

Re: Setting DependencyProperty via EventTrigger

26 Oct 2017, 10:36

Will do next week!

Who is online

Users browsing this forum: Google [Bot] and 1 guest