namespace
Infrastructure
{
using
System;
using
System.Windows;
using
System.Windows.Interactivity;
using
Microsoft.Practices.Prism.Interactivity.InteractionRequest;
using
Telerik.Windows.Controls;
public
interface
IRadDialog : INotification
{
bool
? DialogResult {
get
;
set
; }
DialogParameters DialogParameters {
get
;
set
; }
string
PromptResult {
get
;
set
; }
}
internal
interface
IRadConfirmation : IRadDialog
{
}
internal
interface
IRadAlert : IRadDialog
{
}
internal
interface
IRadPrompt : IRadDialog
{
}
public
abstract
class
RadDialog : Notification
{
public
bool
? DialogResult {
get
;
set
; }
public
DialogParameters DialogParameters {
get
;
set
; }
public
string
PromptResult {
get
;
set
; }
}
public
class
RadConfirmation : RadDialog, IRadConfirmation
{
}
public
class
RadAlert : RadDialog, IRadAlert
{
}
public
class
RadPrompt : RadDialog, IRadPrompt
{
}
/// <summary>
/// Shows a popup window in response to an <see cref="Microsoft.Practices.Prism.Interactivity.InteractionRequest"/> being raised.
/// </summary>
public
class
RadDialogPopupWindowAction : TriggerAction<FrameworkElement>
{
/// <summary>
/// Displays the child window and collects results for <see cref="IInteractionRequest"/>.
/// </summary>
/// <param name="parameter">The parameter to the action. If the action does not require a parameter, the parameter may be set to a null reference.</param>
protected
override
void
Invoke(
object
parameter)
{
var args = parameter
as
InteractionRequestedEventArgs;
if
(args ==
null
)
{
return
;
}
var dialog = args.Context
as
IRadDialog;
var callback = args.Callback;
EventHandler<WindowClosedEventArgs> handler =
null
;
handler =
(o, e) =>
{
dialog.DialogParameters.Closed -= handler;
dialog.DialogResult = e.DialogResult;
dialog.PromptResult = e.PromptResult;
if
(callback !=
null
) callback();
};
dialog.DialogParameters.Closed += handler;
dialog.DialogParameters.Owner = Window.GetWindow(
this
.AssociatedObject);
if
(args.Context
is
IRadPrompt)
{
RadWindow.Prompt(dialog.DialogParameters);
}
else
if
(args.Context
is
IRadAlert)
{
RadWindow.Alert(dialog.DialogParameters);
}
else
if
(args.Context
is
IRadConfirmation)
{
RadWindow.Confirm(dialog.DialogParameters);
}
}
}
}