2017-10-18 6 views
0

私はPrismLibraryのWPFサンプルを具体的にはhttps://github.com/PrismLibrary/Prism-Samples-Wpf/tree/master/6-ViewActivationDeactivationに見ています。私の目標は、ViewActivationDeactivationソリューションの実際のバージョンを作成することですが、代わりにMeFBootstrapperを使用して、UnityBoostrapperを元の例で使用しています。xamlでRegionNameを設定するとMefBootstrapperが例外をスローするWPFアプリケーションでビューをアクティブ/非アクティブにする

私はこの

public class Bootstrapper : MefBootstrapper 
{ 
    protected override void ConfigureAggregateCatalog() 
    { 
     AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(Bootstrapper).Assembly)); 
     base.ConfigureAggregateCatalog(); 
    } 
    protected override DependencyObject CreateShell() 
    { 
     return Container.GetExportedValue<MainWindow>(); 
    } 

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

    protected override CompositionContainer CreateContainer() 
    { 
     var container = base.CreateContainer(); 
     container.ComposeExportedValue(container); 
     return container; 
    } 
} 

ように私のブートストラップクラスを設定していると、メインウィンドウのコードは次のようになります。

XAML

<Window x:Class="DuoApp_ViewNav.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
     xmlns:local="clr-namespace:DuoApp_ViewNav" 
     xmlns:v="clr-namespace:DuoApp_ViewNav.Views" 
      xmlns:prism="http://prismlibrary.com/" 
     mc:Ignorable="d" 
     Title="MainWindow" Height="350" Width="525"> 
    <DockPanel LastChildFill="True"> 
     <ContentControl prism:RegionManager.RegionName="ContentRegion" HorizontalAlignment="Center" VerticalAlignment="Center" /> 
    </DockPanel> 
</Window> 

xaml.cs

[Export] 
public partial class MainWindow : Window 
{ 
    private CompositionContainer _container; 
    private IRegionManager _regionManager; 
    IRegion _region; 

    ViewA _viewA; 
    ViewB _viewB; 

    [ImportingConstructor] 
    public MainWindow(CompositionContainer container, IRegionManager regionManager) 
    { 
     InitializeComponent(); 
     _container = container; 
     _regionManager = regionManager; 

     this.Loaded += MainWindow_Loaded; 
    } 

    private void MainWindow_Loaded(object sender, RoutedEventArgs e) 
    { 
     _viewA = _container.GetExportedValue<ViewA>(); 
     _viewB = _container.GetExportedValue<ViewB>(); 

     _region = _regionManager.Regions["ContentRegion"]; 

     _region.Add(_viewA); 
     _region.Add(_viewB); 
    } 
} 

私が直面しています問題は、取得しようとしながら

アクティベーションエラーが発生しているContentControlに 以内に内部例外メッセージをRegionNameを設定しようとしたときにそれはSystem.Windows.Markup.XamlParseExceptionをスローし、メインウィンドウの初期化に失敗したということですタイプ DelayedRegionCreationBehavior、ここでキー ""

のインスタンス例外詳細

System.Windows.Markup.XamlParseExceptionがを発生しました HResult = -2146233087 LineNumber = 12 LinePosition = 10 Message = 'Set ' Prism.Regions.RegionManager.RegionName 'プロパティが例外をスローしました。 行番号 '12'および行位置 '10'。
ソース= PresentationFrameworkのStackTrace: System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader、IXamlObjectWriterFactory writerFactory、ブール skipJournaledProperties、オブジェクトrootObject、XamlObjectWriterSettings 設定、ウリBASEURI) でSystem.Windows.Markup.WpfXamlLoader.LoadBamlで(xamlReader xamlReader、ブールskipJournaledProperties、オブジェクトrootObject、 XamlAccessLevel ACCESSLEVEL、ウリBASEURI)System.Windows.Application.LoadComponentでSystem.Windows.Markup.XamlReader.LoadBaml(ストリームstream、ParserContext parserContext、オブジェクトの親、ブールcloseStream) で(Objectコンポーネント、Uri resourceLocator) at DuoApp_ViewNav.MainWindow.InitializeComponent()i nはC:プロジェクト\ DuoApp_ViewNav \ DuoApp_ViewNav \ MainWindow.xaml \ Visual Studioの 2015 \ \ Users \ユーザーralfaro \ドキュメント:ライン1
のInnerException:タイプDelayedRegionCreationBehaviorのインスタンスを取得しようとしているときに HRESULT = -2146233088 メッセージ=アクティベーションエラーが発生しました、キー "" ソース= Microsoft.Practices.ServiceLocation のStackTrace: CでMicrosoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstanceで (タイプ サービス種別、文字列のキー):プロジェクト\ CommonServiceLocator \メイン\ Microsoft.Practices.ServiceLocation \ \ ServiceLocatorImplBase.cs:line at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstanceTServic e in c:\ Projects \ CommonServiceLocator \ main \ Microsoft.Practices.ServiceLocation \ ServiceLocatorImplBase。CS:System.Windows.DependencyObject.OnPropertyChangedにおけるライン 90 Prism.Regions.RegionManager.CreateRegion(のDependencyObject素子) でPrism.Regions.RegionManager.OnSetRegionNameCallbackで(のDependencyObject 要素、DependencyPropertyChangedEventArgs引数) (DependencyPropertyChangedEventArgs E) System.Windows.DependencyObject.UpdateEffectiveValue(entryIndex entryIndex、DPたDependencyProperty、PropertyMetadaでSystem.Windows.FrameworkElement.OnPropertyChanged System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs 引数)で(DependencyPropertyChangedEventArgs E) でSystem.Windows.DependencyObject.SetValueCommon(DPたDependencyProperty、 オブジェクト値、PropertyMetadataメタデータ、ブール coerceWithDeferredReference、ブールcoerceWithCurrentValue、 でTAメタデータ、 EffectiveValueEntry oldEntry、EffectiveValueEntry & newEntry、ブール coerceWithDeferredReference、ブールcoerceWithCurrentValue、 OPERATIONTYPE OPERATIONTYPE) MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValueでSystem.Windows.Baml2006.WpfMemberInvoker.SetValue(オブジェクトインスタンス、 オブジェクト値) でOPERATIONTYPE OPERATIONTYPE、ブールisInternal) (XamlMember部材、 オブジェクトobj、Object値)MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValueで(オブジェクト工大、 XamlMemberプロパティ、オブジェクト値) のInnerException:タイプDelayedRegionCreationBehaviorのインスタンスを取得しようとしたとき HRESULT = -2146233088 メッセージ=アクティベーションエラーが発生し、キー "" ソース= Microsoft.Practices.Prism.MefExtensions のStackTrace:Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(タイプ のServiceTypeでMicrosoft.Practices.Prism.MefExtensions.MefServiceLocatorAdapter.DoGetInstance(タイプ サービス種別、文字列のキー) で 、文字列キー) c:\ Projects \ CommonServiceLocator \ main \ Microsoft.Practices.ServiceLocation \ ServiceLocat orImplBase.cs:ラインのInnerException:

は、正直なところ、私はこの例外がスローされる理由はわかりません。私はMefBootstrapperでこの作業をするために何かを見逃していますか?

答えて

0

最後にこれを理解しました。 MefBootstrapperの実装であるPrism.MefとPrism.MefExtensionsを持つ2つのアセンブリを誤って参照しました。 Prism.MefExtensionsパッケージ/リファレンスを削除した後、アプリケーションは正常に動作するようになりました。 私が最後にお手伝いしたトラブルシューティングのステップは、Prismライブラリコードをローカルで実行し、そこから必要な参照を追加して、MefExtensionsが不要であることを認識させることでした。

私packages.configファイルの現在のバージョンは、次のようになります

<?xml version="1.0" encoding="utf-8"?> 
<packages> 
    <package id="CommonServiceLocator" version="1.3" targetFramework="net461" /> 
    <package id="Prism.Core" version="6.3.0" targetFramework="net461" /> 
    <package id="Prism.Mef" version="6.3.0" targetFramework="net461" /> 
    <package id="Prism.Wpf" version="6.3.0" targetFramework="net461" /> 
</packages> 

私は、これは他の誰かに役立ちます願っています。

関連する問題