.NET/C# Prism InteractionRequests in WPF

Using Prism’s InteractionRequests, view models can make interaction requests (such as notifications or confirmations) to the view. It seems that WPF support and documentation lacks behind Silverlight, though. Therefore, I compiled a quick example using InteractionRequests in WPF to trigger a message.

View Model

using Microsoft.Practices.Prism.ViewModel;
using Microsoft.Practices.Prism.Interactivity.InteractionRequest;
public class MyViewModel : NotificationObject
   // view can bind to this request
   public InteractionRequest<Notification> MessageRequest 
      private set;
   // constructor
   public MyViewModel()
      MessageRequest = new InteractionRequest<Notification>();
   // trigger message
   private void RaiseMessageRequest(string message)
      MessageRequest .Raise(new Notification() { Title = message });


The action defines what is to happen in the view. I defined a dependency property to a TextBox to display the message (bound to in the view).

using Microsoft.Practices.Prism.Interactivity.InteractionRequest;
using System.Windows.Interactivity;
public class ShowMessageAction : TriggerAction<FrameworkElement>
   // element in view where message will be shown
   public static readonly DependencyProperty TitleBoxProperty =
      DependencyProperty.Register("TitleBox", typeof(TextBox), 
   public TextBox TitleBox
      get { return (TextBox)GetValue(TitleBoxProperty); }
      set { SetValue(TitleBoxProperty, value); }
   protected override void Invoke(object parameter)
      InteractionRequestedEventArgs e = 
         parameter as InteractionRequestedEventArgs;
      if (e != null)
         if (TitleBox != null)
            TitleBox.Opacity = 1.0;
            TitleBox.Text = e.Context.Title;
            // TODO: for example, hide after some time


Required Namespaces


Displaying Message

<TextBox Opacity="0.0" Name="MessageTitleBox"/>
      SourceObject="{Binding MessageRequest}">
         TitleBox="{Binding ElementName=MessageTitleBox}"/>

5 thoughts on “.NET/C# Prism InteractionRequests in WPF

  1. Found a prob, and fixed it. You have a TextBox in the XAML sample, however the DependencyProperty is typed as TextBlock. This results in a null TitleBox property in the ShowMessageAction class. Once I changed from TextBlock to TextBox, all worked.

  2. I think you are right. PRISM WPF Documentation lacks this InteratcionRequest feature.Where is the Source Code?


  3. I just started with WPF and MVVM and am interested in a working sample application using the code above. Is it available somewhere?

  4. Hi Pierre, I can’t find the source project anymore, but I hope the crucial bits and pieces are shown above.

Comments are closed.