Last active
November 16, 2018 20:26
-
-
Save maybe-joe/ed98f2b8e427781384a2 to your computer and use it in GitHub Desktop.
A basic example of how to show a dialog box using prism and the mvvm pattern in wpf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<UserControl x:Class="Example.ToolbarA" | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | |
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" | |
xmlns:interactionRequest="http://www.codeplex.com/prism" | |
mc:Ignorable="d" | |
d:DesignHeight="300" | |
d:DesignWidth="300"> | |
<Grid> | |
<i:Interaction.Triggers> | |
<interactionRequest:InteractionRequestTrigger SourceObject="{Binding NotificationRequest, Mode=OneWay}"> | |
<interactionRequest:PopupWindowAction IsModal="True" CenterOverAssociatedObject="True"/> | |
</interactionRequest:InteractionRequestTrigger> | |
</i:Interaction.Triggers> | |
<Button Command="{Binding Path=RaiseNotificationCommand}">Click Me</Button> | |
</Grid> | |
</UserControl> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Microsoft.Practices.Prism.Commands; | |
using Microsoft.Practices.Prism.Interactivity.InteractionRequest; | |
namespace Example | |
{ | |
public class ToolbarAViewModel | |
{ | |
public ToolbarAViewModel() | |
{ | |
RaiseNotificationCommand = new DelegateCommand(RaiseNotification); | |
NotificationRequest = new InteractionRequest<INotification>(); | |
} | |
public DelegateCommand RaiseNotificationCommand { get; private set; } | |
public InteractionRequest<INotification> NotificationRequest { get; private set; } | |
public string InteractionResultMessage { get; set; } | |
private void RaiseNotification() | |
{ | |
var notification = new Notification | |
{ | |
Content = "Notification Message", | |
Title = "Notification" | |
}; | |
Action<INotification> lambda = _ => | |
{ | |
InteractionResultMessage = "The user was notified."; | |
}; | |
NotificationRequest.Raise(notification, lambda); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment