日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

03、CustomRegions

發布時間:2024/1/17 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 03、CustomRegions 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

    1、將App.xaml中的StartupUri="MainWindow.xaml"刪除。

  2、使用NuGet安裝Prism.Wpf、Prism.Core、Prism.Unity。

  3、添加類“Bootstrapper”,編輯如下:

1 using Microsoft.Practices.Unity; 2 using Prism.Regions; 3 using Prism.Unity; 4 using System.Windows; 5 using System.Windows.Controls; 6 using CustomRegions.Prism; 7 using CustomRegions.Views; 8 9 namespace CustomRegions 10 { 11 public class Bootstrapper:UnityBootstrapper 12 { 13 protected override DependencyObject CreateShell() 14 { 15 return Container.Resolve<MainWindow>(); 16 } 17 18 protected override void InitializeShell() 19 { 20 Application.Current.MainWindow.Show(); 21 } 22 23 protected override RegionAdapterMappings ConfigureRegionAdapterMappings() 24 { 25 RegionAdapterMappings mappings = base.ConfigureRegionAdapterMappings(); 26 mappings.RegisterMapping(typeof(StackPanel), Container.Resolve<StackPanelRegionAdapter>()); 27 return mappings; 28 } 29 } 30 }

  4、創建文件夾Views,將MainWindow.xaml移動到此文件夾中。添加Prism文件夾,添加“StackPanelRegionAdapter.cs”類。

    

1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 using System.Windows; 7 using System.Windows.Controls; 8 using Prism.Regions; 9 10 namespace CustomRegions.Prism 11 { 12 public class StackPanelRegionAdapter:RegionAdapterBase<StackPanel> 13 { 14 public StackPanelRegionAdapter(IRegionBehaviorFactory regionBehaviorFactory) 15 : base(regionBehaviorFactory) 16 { 17 18 } 19 20 protected override void Adapt(IRegion region, StackPanel regionTarget) 21 { 22 region.Views.CollectionChanged += (s, e) => 23 { 24 if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add) 25 { 26 foreach (FrameworkElement element in e.NewItems) 27 { 28 regionTarget.Children.Add(element); 29 } 30 } 31 32 //handle remove 33 }; 34 } 35 36 protected override IRegion CreateRegion() 37 { 38 return new AllActiveRegion(); 39 } 40 } 41 } 1 <Window x:Class="CustomRegions.Views.MainWindow" 2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 4 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 5 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 6 xmlns:local="clr-namespace:CustomRegions.Views" 7 xmlns:prism="http://prismlibrary.com/" 8 mc:Ignorable="d" 9 Title="Shell" Height="450" Width="800"> 10 <Grid> 11 <ContentControl prism:RegionManager.RegionName="ContentRegion"></ContentControl> 12 </Grid> 13 </Window>

?

轉載于:https://www.cnblogs.com/bjxingch/articles/9546855.html

總結

以上是生活随笔為你收集整理的03、CustomRegions的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。