Blend SDK for WPF action does not work

Asked 2 years ago, Updated 2 years ago, 95 views

We have deployed Liveet 1.3 in .NET Framework 4.5.2 to create client applications for WPF.While studying triggers, I have created a custom trigger that has the same functionality as Livet's InteractionMessageTrigger, but sometimes InvokeActions for TriggerBase are invoked at the desired location and InvokeActions for each Action are not performed.Are there any conditions for InvokeAction to run?The following triggers the problem:

public class CustomInteractionMessageTrigger:TriggerBase<FrameworkElement>
{
    public string MessageKey
    {
        get {return(string)GetValue(MessageKeyProperty);}
        set {SetValue (MessageKeyProperty, value);}
    }

    public Interaction Messenger Messenger
    {
        get {return(InteractionMessenger)GetValue(MessengerProperty);}
        set {SetValue (MessengerProperty, value);}
    }

    protected override void OnAttached()
    {
        base.OnAttached();
    }

    protected override void OnDetaching()
    {
        base.OnDetaching();
    }

    private void MessengerPropertyChanged (DependencyPropertyChangedEventArgse)
    {
        if(e.OldValue!=null)
        {
            ((InteractionMessenger)(e.OldValue)) .Raised-=CustomInteractionMessageTrigger_Raised;
        }
        if(e.NewValue!=null)
        {
            ((InteractionMessenger)(e.NewValue)) .Raised+=CustomInteractionMessageTrigger_Raised;
        }
    }

    private void CustomInteractionMessageTrigger_Raised (object sender, InteractionMessageRaisedEventArgse)
    {
        if(e.Message.MessageKey==MessageKey)
        {
            InvokeActions (e.Message);
        }
    }

    public static readonly DependencyProperty MessageKeyProperty=DependencyProperty.Register(
        nameof(MessageKey), 
        type of (string), 
        type of (CustomInteractionMessageTrigger), 
        new PropertyMetadata (null));

    public static readonly DependencyProperty MessengerProperty=DependencyProperty.Register(
        name of (Messenger),
        type of (InteractionMessenger),
        type of (CustomInteractionMessageTrigger),
        new PropertyMetadata(null,(d,e)=>{((CustomInteractionMessageTrigger)d).MessengerPropertyChanged(e);});
}

When I attached a breakpoint to InvokeActions (e.Message) in the above code, I was able to confirm that it was called.I thought that if you call InvokeActions, Action will definitely be performed…

The development environment is Windows 10 (1703) and IDE is VisualStudio 2015 Update 3.

Please let me know if there is a lack of information.
Thank you for your cooperation.

November 14th Add:
When I looked here (https://msdn.microsoft.com/ja-jp/library/dn195735(v=vs.120).aspx), I noticed that I didn't write OnAttached and OnDetaching, so I added it.I also added this because I did not unsubscribe from Raised events when Messenger changed.However, the problem persists.

c# wpf

2022-09-30 14:57

1 Answers

Self-resolved.

The action that was called from this trigger this time inherited Livet's InteractionMessageAction.This class has the InInvokeActionOnlyWhenWindowIsActive が property that specifies whether the action should be taken only when Window is active, and because this was true, InvokeAction was not running only when the window was not active.


2022-09-30 14:57

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.