1

私のプリズム アプリケーションでは、ビューの単一の共有インスタンスを作成したいと考えています。初めてナビゲートしようとするとうまくいきますが、2回目にしようとするとうまくいきません。PartCreationPolicyからに変更SharedするNonSharedと機能しますが、新しいインスタンスが提供されます。これを行う別の方法のオプションはありますか?

[Export(ViewNames.AppView)]
[PartCreationPolicy(CreationPolicy.Shared)] 
public partial class AppMain : UserControl
{
    public AppMain()
    {
        InitializeComponent();
    }
}
4

1 に答える 1

0

You might want to play around with Prism's KeepAlive value for your view. This value determines whether the view should be removed from the region when you navigate away from it. You have two ways of doing this:

  1. Using the RegionMemberLifetime attribute

    [RegionMemberLifetime(KeepAlive = false)]
    [Export(ViewNames.AppView)]
    [PartCreationPolicy(CreationPolicy.Shared)] 
    public partial class AppMain : UserControl
    {
        public AppMain()
        {
            InitializeComponent();
        }
    }
    
  2. Implementing the IRegionMemberLifetime interface

    [Export(ViewNames.AppView)]
    [PartCreationPolicy(CreationPolicy.Shared)] 
    public partial class AppMain : UserControl, IRegionMemberLifetime
    {
        public AppMain()
        {
            InitializeComponent();
        }
    
        public bool KeepAlive
        {
            get { return false; }
        }
    }
    

You can read some more about the KeepAlive property here.

于 2013-06-03T21:31:54.170 に答える