0

我已经使用 Prism 6 实现了 Word 2016 的任务窗格。从该任务窗格中我需要显示一个模式窗口,因此我实现了 prism 自定义交互。窗口是从绑定到委托命令的按钮开始的。在第一次单击时,一切都按预期工作,但是在第二次单击时出现异常。开发环境:VS2015,Office 2016,Windows 10 希望有人能指出我正确的方向。这里有一些更详细的信息:

System.InvalidOperationException occurred
  HResult=-2146233079
  Message=Das Anwendungsobjekt wird beendet.
  Source=PresentationFramework
  StackTrace:
       bei System.Windows.Application.GetResourcePackage(Uri packageUri)
       bei System.Windows.Application.GetResourceOrContentPart(Uri uri)
       bei System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
       bei Prism.Interactivity.DefaultPopupWindows.DefaultWindow.InitializeComponent()
       bei Prism.Interactivity.PopupWindowAction.CreateWindow()
       bei Prism.Interactivity.PopupWindowAction.GetWindow(INotification notification)
       bei Prism.Interactivity.PopupWindowAction.Invoke(Object parameter)
       bei System.Windows.Interactivity.TriggerBase.InvokeActions(Object parameter)
       bei System.Windows.Interactivity.EventTriggerBase.OnEvent(EventArgs eventArgs)
       bei System.Windows.Interactivity.EventTriggerBase.OnEventImpl(Object sender, EventArgs eventArgs)
       bei Prism.Interactivity.InteractionRequest.InteractionRequest`1.Raise(T context, Action`1 callback)
       bei Prism.Interactivity.InteractionRequest.InteractionRequest`1.Raise(T context)
       bei PostOffice.WordPlugIn.ViewModels.TaskPaneViewmodel.OnShowConfirmationClick() in C:\GIT\eZustellung\PostOffice\PostOffice.WordPlugIn\ViewModels\TaskPaneViewmodel.cs:Zeile 39.

触发:

  <!-- Interactions -->
    <i:Interaction.Triggers>
        <!-- All the InteractionRequestTriggers here subscribe to the corresponding interaction requests through simple bindings -->
        <!-- In this case all of them raise a PopupWindowAction, but you can use other actions too -->
        <prism:InteractionRequestTrigger SourceObject="{Binding NewDeliveryRequest, Mode=OneWay}">
            <!-- This PopupWindowAction does not have a custom view defined, therefore it will try to use a DefaultNotificationWindow -->
            <!-- which is a window used by default by Prism to shown INotification implementations -->
            <!-- That window will be show as a modal dialog and centered over this window -->
            <prism:PopupWindowAction WindowStartupLocation="CenterScreen">
                <prism:PopupWindowAction.WindowContent>
                    <newdelivery:NewDeliveryWordView />
                </prism:PopupWindowAction.WindowContent>
            </prism:PopupWindowAction>
        </prism:InteractionRequestTrigger>
    </i:Interaction.Triggers>

提高通知:

 private void OnShowConfirmationClick()
    {
        NewDeliverNotifcation notifcation = new NewDeliverNotifcation();
        notifcation.Title = "New Delivery";
        Ergebnis = "";
        NewDeliveryRequest.Raise(notifcation,callback);

    }

    private void callback(NewDeliverNotifcation obj)
    {
        Ergebnis = obj.OK ? "Super" : "Not super";
    }

自定义确认视图模型:

public class NewDeliveryWordViewmodel : NewDeliveryBaseViewmodel, IInteractionRequestAware
{
    private NewDeliverNotifcation notification;
    public NewDeliveryWordViewmodel()
    {
        ContinueCommand = new DelegateCommand(OnContinueClick);
        CancelCommand = new DelegateCommand(OnCancelClick);

    }

    private void OnCancelClick()
    {
        notification.OK = false;
        FinishInteraction();
    }

    private void OnContinueClick()
    {
        notification.OK = true;
        FinishInteraction();
    }
    public DelegateCommand CancelCommand { get; private set; } 
    public DelegateCommand ContinueCommand { get; private set; }

    public Action FinishInteraction { get; set; }


    public INotification Notification
    {
        get
        {
            return notification;
        }

        set
        {
            if(value is NewDeliverNotifcation)
            {
                notification = value as NewDeliverNotifcation;
                OnPropertyChanged(() => this.Notification);
            }
        }
    }
}
4

1 回答 1

0

好的。最后我解决了。VSTO 任务窗格基于 Winforms。我将它与 WPF Element Host 一起使用,然后我想从那里显示另一个 WPF 窗口。这似乎是问题所在。解决方案:再次使用另一个带有 WPF 元素宿主的 Winform 窗口来显示 WPF 内容。

于 2016-06-28T12:34:11.993 回答