0

I have implemented a TaskPane for Word 2016 using Prism 6. From that Taskpane I need to show a modal window, an so I implemented prism custom interaction. The Window ist started from a button bound to a delegate command. At the first Click everything works as expected, but when clicking the second time I get an exception. Development Environment: VS2015, Office 2016, Windows 10 Hopefully someone can point me in the right direction. Here some more detaild information:

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.

The Trigger:

  <!-- 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>

Raising the notfication:

 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";
    }

The Custom Confirmation Viewmodel:

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);
            }
        }
    }
}
Josef B.
  • 414
  • 4
  • 9

1 Answers1

0

OK. Finally I solved it. VSTO Taskpane is based on Winforms. I used it with the WPF Element Host and from there I wanted to show another WPF Window. That seems to be the problem. Solution: Use another Winform Window again with WPF element host to show WPF content.

Josef B.
  • 414
  • 4
  • 9