0

Prism 6 を使用して Word 2016 の TaskPane を実装しました。その Taskpane からモーダル ウィンドウを表示する必要があるため、prism カスタム インタラクションを実装しました。ウィンドウは、デリゲート コマンドにバインドされたボタンから開始されます。最初のクリックではすべてが期待どおりに機能しますが、2 回目のクリックでは例外が発生します。開発環境: 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 Taskpane は Winforms に基づいています。私は WPF Element Host でそれを使用し、そこから別の WPF ウィンドウを表示したいと考えました。それが問題のようです。解決策: WPF 要素ホストで別の Winform ウィンドウを再度使用して、WPF コンテンツを表示します。

于 2016-06-28T12:34:11.993 に答える