2016-12-18 7 views
2

私のカスタム設定ビューを表示するために、プリズムのPopupWindowActionを使用したインタラクティビティオブジェクトを使用するShellViewがあります。私のShellViewModelには、InteractionRequestオブジェクトと、ユーザーとの対話を開始するDelegate Commandが含まれています。ユーザーが起動すると、カスタム設定ビュー(DataFeedManagerView)がShellViewの中央に表示されます。 My DataFeedManagerViewには、左側にDataFeed(ListBoxコントロール)のリストがあり、右側にはdatafeed固有の設定ビュー(RegionControlからRegionを設定したContentControl)があります。まず、RegisterViewWithRegionですべてのビューを登録しました。次に、リージョンのActivateメソッドを使用してコンテンツコントロール内の関連するオブジェクト設定ビューをアクティブにします。このようにしようとすると、「地域を見つけることができません」というエラーが表示されます。だから我々は、カスタムポップアップウィンドウ内の領域を使用することはできません?リージョンマネージャがカスタムポップアップウィンドウ内の領域を見つけることができません

PS1:おそらくこれは簡単な要件ですが、私の説明が少し複雑だったので、多くのステップが含まれています。私はコードがより記述的であることを願っています。

PS2:私はContentControlのコンテンツプロパティへの単純なバインディングを使用することで期待を満たしています。しかし、私は、カスタムインタラクションポップアップウィンドウ内で使用領域の私の間違いや正しい解決策が何であるか心配です。

.. ::シェル:: ..

<Window x:Class="PrismUnityApp.Views.ShellView" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" 
    xmlns:views="clr-namespace:PrismUnityApp.Views" 
    xmlns:constants="clr-namespace:PrismUnityApp.Constants" 
    xmlns:prism="http://prismlibrary.com/" 
    prism:ViewModelLocator.AutoWireViewModel="True" 
    Title="{Binding Title}" Height="480" Width="640"> 
<DockPanel LastChildFill="True"> 
    <i:Interaction.Triggers> 
     <prism:InteractionRequestTrigger SourceObject="{Binding ConfirmationRequest}"> 
      <prism:PopupWindowAction IsModal="True" CenterOverAssociatedObject="True"> 
       <prism:PopupWindowAction.WindowContent> 
        <views:DataFeedManagerView/> 
       </prism:PopupWindowAction.WindowContent> 
      </prism:PopupWindowAction> 
     </prism:InteractionRequestTrigger> 
    </i:Interaction.Triggers> 
    <Button Content=" Show Data Feed Manager" Command="{Binding ShowDataFeedManagerCommand}"/> 
    <ContentControl prism:RegionManager.RegionName="{x:Static constants:WellKnownRegionNames.ContentRegion}" /> 
</DockPanel> 

using System.Windows.Input; 
using Prism.Commands; 
using Prism.Interactivity.InteractionRequest; 
using Prism.Mvvm; 

namespace PrismUnityApp.ViewModels 
{ 
    public class ShellViewModel : BindableBase 
    { 
     private string _title = "Prism Unity Application"; 
     public ICommand ShowDataFeedManagerCommand { get; } 
     public InteractionRequest<IConfirmation> ConfirmationRequest { get; } 
     public string Title 
     { 
      get { return _title; } 
      set { SetProperty(ref _title, value); } 
     } 
     public ShellViewModel() 
     { 
      ConfirmationRequest = new InteractionRequest<IConfirmation>(); 
      ShowDataFeedManagerCommand = new DelegateCommand(ShowDataFeedManager); 
     } 
     public void ShowDataFeedManager() 
     { 
      ConfirmationRequest.Raise(
       new Confirmation {Title = "Data Feed Manager", Content = string.Empty}, 
       confirmation => 
       { 
       }); 
     } 
    } 
} 

.. :: DataFeedManager :: ..

<UserControl x:Class="PrismUnityApp.Views.DataFeedManagerView" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:constants="clr-namespace:PrismUnityApp.Constants" 
     xmlns:prism="http://prismlibrary.com/" 
     xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" 
     prism:ViewModelLocator.AutoWireViewModel="True" 
     Height="240" Width="320"> 
<DockPanel LastChildFill="True"> 
    <ListBox 
     SelectedItem="{Binding Current, Mode=OneWay}" 
     ItemsSource="{Binding DataFeeds}"> 
     <i:Interaction.Triggers> 
      <i:EventTrigger EventName="SelectionChanged"> 
       <prism:InvokeCommandAction 
        Command="{Binding SelectionChangedCommand}" 
        CommandParameter="{Binding SelectedItem, RelativeSource={RelativeSource Self}}"></prism:InvokeCommandAction> 
      </i:EventTrigger> 
     </i:Interaction.Triggers> 
     <ListBox.ItemTemplate> 
      <DataTemplate> 
       <TextBlock Text="{Binding Key}"></TextBlock> 
      </DataTemplate> 
     </ListBox.ItemTemplate> 
    </ListBox> 
    <ContentControl prism:RegionManager.RegionName="{x:Static constants:WellKnownRegionNames.DataFeedRegion}"></ContentControl> 
</DockPanel> 

using System.Collections.Generic; 
using System.Linq; 
using System.Windows.Controls; 
using System.Windows.Input; 
using Microsoft.Practices.Unity; 
using Prism.Commands; 
using Prism.Mvvm; 
using Prism.Regions; 
using PrismUnityApp.Constants; 
using PrismUnityApp.Interfaces; 

namespace PrismUnityApp.ViewModels 
{ 
    public class DataFeedManagerViewModel : BindableBase, IDataFeedManagerViewModel 
    { 
     private readonly IRegionManager _regionManager; 
     public IDictionary<string, object> DataFeeds { get; } 
     public ICommand SelectionChangedCommand { get; } 
     public DataFeedManagerViewModel(IUnityContainer unityContainer, IRegionManager regionManager) 
     { 
      _regionManager = regionManager; 

      SelectionChangedCommand = new DelegateCommand<SelectionChangedEventArgs>(SelectionChanged); 

      DataFeeds = new Dictionary<string, object> 
      { 
       {WellKnownDataFeedNames.SimulationDataFeed, unityContainer.Resolve<ISimulationDataFeedView>()}, 
       {WellKnownDataFeedNames.BarchartDataFeed, unityContainer.Resolve<IBarchartDataFeedView>()} 
      }; 

      foreach (var dataFeed in DataFeeds) 
       _regionManager.RegisterViewWithRegion(WellKnownRegionNames.DataFeedRegion,() => dataFeed.Value); 
     } 
     public void SelectionChanged(SelectionChangedEventArgs e) 
     { 
      var addedItem = (KeyValuePair<string, object>) e.AddedItems[0]; 
      var region = _regionManager.Regions[WellKnownRegionNames.DataFeedRegion]; 
      region.Activate(addedItem.Value); 
     } 
    } 
} 

.. ::ブートストラップあなたはこのように、後ろのポップアップビューのコード(コンストラクタ)に、手動で地域マネージャを設定する必要がありますおそらく、:: ..

using System.Windows; 
using Microsoft.Practices.Unity; 
using Prism.Unity; 
using PrismUnityApp.Interfaces; 
using PrismUnityApp.ViewModels; 
using PrismUnityApp.Views; 

namespace PrismUnityApp 
{ 
    class Bootstrapper : UnityBootstrapper 
    { 
     #region Overrides of UnityBootstrapper 

     protected override void ConfigureContainer() 
     { 
      base.ConfigureContainer(); 
      Container.RegisterType<ISimulationDataFeedView, SimulationDataFeedView>(); 
      Container.RegisterType<ISimulationDataFeedViewModel, SimulationDataFeedViewModel>(); 
      Container.RegisterType<IBarchartDataFeedView, BarchartDataFeedView>(); 
      Container.RegisterType<IBarchartDataFeedViewModel, BarchartDataFeedViewModel>(); 
      Container.RegisterType<IDataFeedManagerView, DataFeedManagerView>(); 
      Container.RegisterType<IDataFeedManagerViewModel, DataFeedManagerViewModel>(); 
     } 

     protected override DependencyObject CreateShell() 
     { 
      return Container.Resolve<ShellView>(); 
     } 

     protected override void InitializeShell() 
     { 
      Application.Current.MainWindow.Show(); 
     } 

     #endregion 
    } 
} 

答えて

3

RegionManager.SetRegionName(theNameOfTheContentControlInsideThePopup, WellKnownRegionNames.DataFeedRegion); 
RegionManager.SetRegionManager(theNameOfTheContentControlInsideThePopup, theRegionManagerInstanceFromUnity); 

あなた'LLそのリージョンをホストしているコンテンツコントロールに名前を割り当て、何らかの形でリージョンマネージャー()を取得する必要があります。

+0

RegionManagerのSetRegionNameおよびSetRegionManagerメソッドはどこにありますか? –

+0

これは型で呼び出された静的メンバーであり、具体的な 'IRegionManager'インスタンスではありません – Haukinger

+0

私の問題は解決しましたが、ソリューションはMVVMパターンを破るのですか?またはPrism Libraryに関するバグのような問題ですか?わからない。これらの問題についてのあなたの考えは? –