首页 > 其他分享 >Region

Region

时间:2023-03-18 22:47:00浏览次数:34  
标签:Region public Add ViewA IRegion 适配器

1.内置区域适配器

  ContentControlRegionAdapter、ItemControlRegionAdapter、SelectorRegionAdapter、Combobox、ListBox、Ribbon、TabControl

  使用:

    view中:

      <ContentControl prism:RegionManager.RegionName="ContentRegion" />

    ViewModel中:      

      public MainWindowViewModel(IRegionManager regionManager)
      {

        //ViewA是一个用户控件
        regionManager.RegisterViewWithRegion("ContentRegion", typeof(ViewA));
      }

2.自定义区域适配器

    public class StackPanelRegionAdapter : RegionAdapterBase<StackPanel>
    {
        public StackPanelRegionAdapter(IRegionBehaviorFactory regionBehaviorFactory) : base(regionBehaviorFactory)
        {
        }

        protected override void Adapt(IRegion region, StackPanel regionTarget)
        {
            region.Views.CollectionChanged += (s, e) =>
            {
                if(e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
                {
                    foreach (FrameworkElement item in e.NewItems)
                    {
                        regionTarget.Children.Add(item);
                    }
                }
            };
        }

        protected override IRegion CreateRegion()
        {
            return new Region();
        }
    }

  使用:<StackPanel prism:RegionManager.RegionName="ContentRegion"/>

标签:Region,public,Add,ViewA,IRegion,适配器
From: https://www.cnblogs.com/chixiner/p/17232053.html

相关文章