Search This Blog

Wednesday, August 31, 2011

Show PRISM message box; Display message box using PRISM MVVM Silverlight

We want to display a message box with the help of PRISM in Silverlight.
There is a different class for displaying an question - Confirmation. We
can display our own window with InteractionRequest<OurViewModel> and some code in XAML
defining which view to run.

Message box class in defined in PRISM's namespace:
namespace: Microsoft.Practices.Prism.Interactivity.InteractionRequest

Class name is Notification.

SomeView, XAML:

<UserControl x:Class="WebClient.SomeView"
..... >

    <Grid x:Name="LayoutRoot" Background="White">
            <prism:InteractionRequestTrigger SourceObject="{Binding SaveNotification}">

SomeViewModel, cs:

public class SomeViewModel
    public SomeViewModel(......)
        saveNotification = new InteractionRequest<Notification>();

    private readonly InteractionRequest<Notification> saveNotification;

    //this function displays message box
    private void someFunction(object obj)
        //show message box
        ((InteractionRequest<Notification>)saveNotification).Raise(new Notification { Title = "Information", Content = "User was saved." });           

    public IInteractionRequest SaveNotification
        get { return this.saveNotification; }

1 comment:

If you like this post, please leave a comment :)