0

在 WPF 中是否有任何替代方法,此标签的性质是在您执行任何特定操作之前启用确认对话框。

在 silverlight 下支持此标签,但不幸的是,在 WPF 下似乎缺少此标签。不确定这个 Prism 团队是否不小心错过了什么。上述标签的最佳替代品是什么?

4

1 回答 1

1

您基本上必须创建自己的。但是,我之前发现了一个例子,有人做了一个。我对 Prism 的交互类进行了相当多的修改,所以我的 ModalPopupAction 可能与您需要的有所不同。因此,请查看此链接并下载他的示例。它有一个WPF的实现!

Prism:用于 WPF 应用程序的 InteractionRequest 和 PopupModalWindowAction

如果你想知道......我的 ModalPopupAction 看起来像这样(但它需要我的一些其他类)

public class ModalPopupAction : TriggerAction<FrameworkElement>
{
    public UserControl InteractionView
    {
        get { return (UserControl)GetValue(InteractionViewProperty); }
        set { SetValue(InteractionViewProperty, value); }
    }

    // Using a DependencyProperty as the backing store for PopupDialog.  This enables animation, styling, binding, etc...
    public static readonly DependencyProperty InteractionViewProperty =
        DependencyProperty.Register("InteractionView", typeof(UserControl), typeof(ModalPopupAction), new UIPropertyMetadata(null));

    protected override void Invoke(object parameter)
    {
        InteractionRequestedEventArgs args = parameter as InteractionRequestedEventArgs;

        if (args == null)
            return;

        // create the window
        ModalPopupDialog dialog = new ModalPopupDialog();
        dialog.Content = InteractionView;

        // set the data context
        dialog.DataContext = args.Interaction;

        // handle finished event
        EventHandler handler = null;
        handler = (o, e) =>
        {
            dialog.Close();
            args.Callback();
        };
        args.Interaction.Finished += handler;

        // center window
        DependencyObject current = AssociatedObject;
        while (current != null)
        {
            if (current is Window)
                break;
            current = LogicalTreeHelper.GetParent(current);
        }
        if (current != null)
            dialog.Owner = (current as Window);

        dialog.ShowDialog();
        dialog.Content = null;
        dialog.DataContext = null;
        args.Interaction.Finished -= handler;
    }
}
于 2013-06-28T13:35:51.253 回答