2017-01-02 77 views
0

我正在實現一些交互性使用棱鏡來顯示一個按鈕後彈出窗體。但彈出窗口沒有顯示。交互請求提高不顯示彈出(棱鏡 - 交互性)

這是我的視圖,其中該按鈕被定義(ContactsView):

<i:Interaction.Triggers> 
    <prism:InteractionRequestTrigger SourceObject="{Binding ContactInteractionRequest, Mode=OneWay}"> 
     <prism:PopupWindowAction> 
      <prism:PopupWindowAction.WindowContent> 
       <views:AddContactPopupView /> 
      </prism:PopupWindowAction.WindowContent> 
     </prism:PopupWindowAction> 
    </prism:InteractionRequestTrigger> 
</i:Interaction.Triggers> 

<Grid> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="30" /> 
     <RowDefinition Height="*" /> 
    </Grid.RowDefinitions> 

    <DockPanel Grid.Row="0" Background="#D6D6DC"> 
     <ToolBar Style="{StaticResource ModuleToolBarStyle}"> 
      <TextBlock Margin="10,0,0,0" Text="Contacts"></TextBlock> 
      <Button Name="addContactButton" ToolTip="Add Contact" 
        Command="{Binding RaiseAddContactInteractionCommand}"> 
       <Image Source="/PrismApp.Controls;component/Images/add.png"/> 
      </Button> 
      ... 
     </ToolBar> 
    </DockPanel> 
    ... 
</Grid> 

這是AddContactPopupView:

<UserControl x:Class="PrismApp.Modules.Configuration.Contacts.Views.AddContactPopupView" 
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      xmlns:prism="http://prismlibrary.com/" 
      prism:ViewModelLocator.AutoWireViewModel="True" 
      mc:Ignorable="d" 
      d:DesignHeight="700" d:DesignWidth="500"> 
    <Grid> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="30" /> 
      <RowDefinition Height="*" /> 
     </Grid.RowDefinitions> 

     <DockPanel Grid.Row="0"> 
      <ToolBar Style="{StaticResource ModuleToolBarStyle}"> 
       <TextBlock Margin="10,0,0,0" Text="Add contact"/> 
       <Button Name="addAndCloseButton" ToolTip="Add Contact" Command="{Binding ConfirmCommand}"> 
        <Image Source="/PrismApp.Controls;component/Images/add.png"/> 
       </Button> 
       <Button Name="cancelButton" ToolTip="Cancel" Command="{Binding CancelCommand}"> 
        <Image Source="/PrismApp.Controls;component/Images/cancel.png"/> 
       </Button> 
      </ToolBar> 
     </DockPanel> 
     <Grid Margin="0,0,7,0" Grid.Row="1"> 
      ... 
      <!-- User controls to fill the contact details --> 
     </Grid> 
    </Grid> 
</UserControl> 

這是AddContactPopupViewModel:

public class AddContactPopupViewModel : BindableBase, IInteractionRequestAware 
{ 
    private ContactNotification notification; 

    public AddContactPopupViewModel() 
    { 
     this.ConfirmCommand = new DelegateCommand(this.AcceptContactConfiguration); 
     this.CancelCommand = new DelegateCommand(this.CancelInteraction); 
    } 

    public Action FinishInteraction { get; set; } 

    public INotification Notification 
    { 
     get 
     { 
      return this.notification; 
     } 
     set 
     { 
      if (value is ContactNotification) 
      { 
       this.notification = value as ContactNotification; 
       this.OnPropertyChanged(() => this.Notification); 
      } 
     } 
    } 

    public ICommand ConfirmCommand { get; private set; } 

    public ICommand CancelCommand { get; private set; } 

    public void AcceptContactConfiguration() 
    { 
     if (this.notification != null) 
     { 
      this.notification.Confirmed = true; 
     } 

     this.FinishInteraction(); 
    } 

    public void CancelInteraction() 
    { 
     if (this.notification != null) 
     { 
      this.notification.Name = null; 
      this.notification.LastName = null; 
      this.notification.Telephone1 = null; 

      this.notification.Confirmed = false; 
     } 

     this.FinishInteraction(); 
    } 
} 

這是ContactNotification自定義類:

public class ContactNotification : Confirmation 
{ 
    public ContactNotification() 
    { 

    } 
    public string Name { get; set; } 
    public string LastName { get; set; } 
    public string Telephone1 { get; set; } 
} 

最後,這是ContactsViewModel:

public class ContactsViewModel : BindableBase 
{ 
    private readonly IRegionManager regionManager; 
    private readonly IEventAggregator eventAggregator; 
    private readonly IConfigurationContactsService contactsService; 

    private readonly DelegateCommand<object> deleteContactCommand; 

    private ObservableCollection<Contact> contactsCollection; 
    private ICollectionView contactsView; 

    public ContactsViewModel(IEventAggregator eventAggregator, IConfigurationContactsService contactsService, IRegionManager regionManager) 
    { 
     this.regionManager = regionManager; 
     this.contactsService = contactsService; 
     this.eventAggregator = eventAggregator; 

     this.deleteContactCommand = new DelegateCommand<object>(this.DeleteContact, this.CanDeleteContact); 

     this.contactsCollection = new ObservableCollection<Contact>(contactsService.GetContacts()); 
     this.contactsView = CollectionViewSource.GetDefaultView(this.contactsCollection); 

     this.ContactInteractionRequest = new InteractionRequest<ContactNotification>(); // Here is the InteractionRequest instantiated 
     this.RaiseAddContactInteractionCommand = new DelegateCommand(this.RaiseAddContactInteraction); 
    } 

    public ICollectionView ContactsView 
    { 
     get { return this.contactsView; } 
    } 
    public ObservableCollection<Contact> Contacts 
    { 
     get { return this.contactsCollection; } 
    } 

    public ICommand DeleteContactCommand 
    { 
     get { return this.deleteContactCommand; } 
    } 

    private void DeleteContact(object ignore) 
    { 
     IList<Contact> selectedContacts = contactsService.GetSelectedContacts(); 
     foreach (Contact contact in selectedContacts) 
     { 
      if (contact != null) 
      { 
       contactsService.DeleteContact(contact); 
       Contacts.Remove(contact); 
      } 
     } 
    } 
    private bool CanDeleteContact(object ignored) 
    { 
     return true; 
    } 

    public InteractionRequest<ContactNotification> ContactInteractionRequest { get; private set; } 
    public ICommand RaiseAddContactInteractionCommand { get; private set; } 
    private void RaiseAddContactInteraction() 
    { 
     ContactNotification notification = new ContactNotification(); 
     notification.Title = "New contact"; 

     this.ContactInteractionRequest.Raise(notification, 
      returned => 
      { 
       if (returned != null && returned.Confirmed) 
       { 
        var result = contactsService.AddContact(new Contact 
        { 
         Name = returned.Name, 
         LastName = returned.LastName, 
         Telephone1 = returned.Telephone1, 
        }); 

        if (!result) 
         throw new NotImplementedException("TODO: Handle this"); 

        SetProperty<ObservableCollection<Contact>>(ref this.contactsCollection, new ObservableCollection<Contact>(contactsService.GetContacts()), "Contacts"); 
       } 
       else 
       { 
        // TODO 
       } 
      }); // After this, AddContactPopup should popup in a new window. But nothing happens 
    } 
} 

ContactInteractionRequest.Raise被調用後,一個新的窗口會彈出,但沒有任何反應。我正在努力尋找問題。任何想法在哪裏看?

+0

確保僅創建ContactsViewModel類的一個實例,並通過在方法中設置斷點並調試您的應用程序來調用此特定實例的RaiseAddContactInteraction()方法。 – mm8

+0

是的。當我將視圖模型註冊爲單例並且RaiseAddContactInteraction()被擊中時,只創建一個實例。該行被執行:「this.ContactInteractionRequest.Raise(notification,returned => ...」但是窗口不會彈出。 – chincheta73

+0

如果您嘗試使用更簡單的窗口內容,該怎麼辦?: test ...。如果這個工作有可能是你的AddContactPopupView錯誤 – mm8

回答

1

Any ideas where to look at?

你必須清理你的參考。混合棱鏡5和棱鏡6不太好,或者說,根本不起作用。

因此,請刪除您的packages.config和項目參考相關的所有棱鏡,然後從nuget添加棱鏡6(我剛添加Prism.Unity,它帶來了所需的一切)。然後,您必須更正某些using和模塊配置app.config<section name="modules" type="Prism.Modularity.ModulesConfigurationSection, Prism.Wpf" />,並且彈出窗口按預期顯示。

+0

嗨,謝謝你的回答。我正在按照您的步驟操作,但在編譯期間,我在Bootstrapper的ConfigureRegionAdapterMappings()方法中出現錯誤,該錯誤無法修復。這是錯誤:''Microsoft.Practices.Unity.IUnityContainer'不包含'解決'的定義和最佳擴展方法重載'Microsoft.Practices.Unity.UnityContainerExtensions.Resolve (Microsoft.Practices.Unity.IUnityContainer, params Microsoft.Practices.Unity.ResolverOverride [])'有一些無效的參數'。你是如何解決這個錯誤的?這是否也發生在你身上? – chincheta73

+0

我在刪除棱鏡5的東西后看到了100多個這樣的錯誤,但是當我刪除過時的使用並添加棱鏡6時,所有這些都消失了... – Haukinger

+0

我剛剛得到一個混亂,因爲我不知道哪個用於棱鏡6而不是。您能請分享一個修正項目的鏈接嗎? – chincheta73