2016-01-09 37 views
1

我有一個使用彈出窗口的Prism WPF應用程序。多個地方需要相同的功能,所以我的彈出引用如此。WPF,C#:彈出創建問題的多個聲明

<i:Interaction.Triggers> 
    <interactionRequest:InteractionRequestTrigger SourceObject="{Binding CreateCatalogsRequest, Mode=OneWay}"> 
     <interactionRequest:PopupWindowAction> 
      <interactionRequest:PopupWindowAction.WindowContent> 

       <!-- Problem line below --> 
       <view:SomePopUpView /> 

      </interactionRequest:PopupWindowAction.WindowContent> 
     </interactionRequest:PopupWindowAction> 
    </interactionRequest:InteractionRequestTrigger> 
</i:Interaction.Triggers> 

此時完全相同的代碼片段出現在兩個控件中。當我註釋掉代碼,或用一個標準組件(Combobox)替換「SomePopupView」時,我的應用程序就可以工作。當我有兩次引用相同的組件(SomePopupView)時,我的應用程序扼殺了區域。

我不想重寫或擴展或做任何架構巫術,但我如何在應用程序的不同部分獲得相同的彈出功能?

由AnjumSKhan提供作品的任何幫助感激

EDIT溶液。我的解決方案如下

的App.xaml

<Application.Resources> 
    <view:SomePopupView x:Key="SomePopupView" /> 
    .... 
<Application.Resources> 

查看與重複彈出

<i:Interaction.Triggers> 
    <interactionRequest:InteractionRequestTrigger SourceObject="{Binding CreateRequestInteraction, Mode=OneWay}"> 
     <interactionRequest:PopupWindowAction> 
      <interactionRequest:PopupWindowAction.WindowContent> 
       <ContentControl Content="{StaticResource SomePopupView}"></ContentControl> 
      </interactionRequest:PopupWindowAction.WindowContent> 
     </interactionRequest:PopupWindowAction> 
    </interactionRequest:InteractionRequestTrigger> 
</i:Interaction.Triggers> 
+1

聲明你的'Popup'作爲'Resource'。 – AnjumSKhan

+0

將您的解決方案發布爲答案並接受它,以便其他人可以清楚地看到這是一個解決的問題。 – Bart

回答

0

解決方案。

的App.xaml

<Application.Resources> 
    <view:SomePopupView x:Key="SomePopupView" /> 
    .... 
<Application.Resources> 

查看與重複彈出

<i:Interaction.Triggers> 
    <interactionRequest:InteractionRequestTrigger SourceObject="{Binding CreateRequestInteraction, Mode=OneWay}"> 
     <interactionRequest:PopupWindowAction> 
      <interactionRequest:PopupWindowAction.WindowContent> 
       <ContentControl Content="{StaticResource SomePopupView}"></ContentControl> 
      </interactionRequest:PopupWindowAction.WindowContent> 
     </interactionRequest:PopupWindowAction> 
    </interactionRequest:InteractionRequestTrigger> 
</i:Interaction.Triggers>