bovender framework
C# framework that implements MVVM and more
MessageActionExtensions.cs
1 using System;
2 /* MessageActionExtensions.cs
3  * part of Daniel's XL Toolbox NG
4  *
5  * Copyright 2014-2018 Daniel Kraus
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 using System.Windows.Interactivity;
20 using Bovender.Mvvm.Messaging;
21 
22 namespace Bovender.Mvvm.Actions
23 {
24  public static class MessageActionExtensions
25  {
41  public static void Invoke(this MessageActionBase action, EventArgs messageArgs)
42  {
43  NonUiTrigger trigger = new NonUiTrigger();
44  trigger.Actions.Add(action);
45 
46  try
47  {
48  trigger.Invoke(messageArgs);
49  }
50  finally
51  {
52  trigger.Actions.Remove(action);
53  }
54  }
55 
56  public static void InvokeWithContent<T>(this MessageActionBase action, T messageContent)
57  where T: MessageContent
58  {
59  NonUiTrigger trigger = new NonUiTrigger();
60  trigger.Actions.Add(action);
61 
62  try
63  {
64  trigger.Invoke(new MessageArgs<T>(messageContent, null));
65  }
66  finally
67  {
68  trigger.Actions.Remove(action);
69  }
70  }
71 
72 
77  public static void Invoke(this MessageActionBase action)
78  {
79  action.Invoke(new MessageArgs<MessageContent>(new MessageContent(), null));
80  }
81  }
82 }
static void Invoke(this MessageActionBase action)
Invokes a TriggerAction and sets the Content property to a newly created Messaging.MessageArgs object .
static void Invoke(this MessageActionBase action, EventArgs messageArgs)
Invokes a TriggerAction with the specified parameter.
void Invoke(object parameter)
Invokes the trigger&#39;s actions.
Definition: NonUiTrigger.cs:35
Abstract base class for MVVM messaging actions.
A trigger that may be invoked from code.
Definition: NonUiTrigger.cs:29
Simple object that encapsulates a boolean value; to be used in MVVM interaction with MessageArgs...
override void Invoke(object parameter)
Invokes the action by creating a view and a corresponding view model.