成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

C# 一個基于.NET Core3.1的開源項目幫你徹底搞懂WPF框架Prism

開發 項目管理 開源
MainWindow.xaml.cs:這里在窗體構造函數中注入了一個容器擴展接口和一個regin管理器接口,分別用來裝載視圖和注冊regin,窗體的激活和去激活分別通過regions的Activate和Deactivate方法實現。

概述

這個項目演示了如何在WPF中使用各種Prism功能的示例。如果您剛剛開始使用Prism,建議您從第一個示例開始,按順序從列表中開始。每個示例都基于前一個示例的概念。

此項目平臺框架:.NET Core 3.1

Prism版本:8.0.0.1909

提示:這些項目都在同一解決方法下,需要依次打開運行,可以選中項目-》右鍵-》設置啟動項目,然后運行:

目錄介紹

Topic

描述

Bootstrapper and the Shell

創建一個基本的引導程序和shell

Regions

創建一個區域

Custom Region Adapter

為StackPanel創建自定義區域適配器

View Discovery

使用視圖發現自動注入視圖

View Injection

使用視圖注入手動添加和刪除視圖

View Activation/Deactivation

手動激活和停用視圖

Modules with App.config

使用應用加載模塊。配置文件

Modules with Code

使用代碼加載模塊

Modules with Directory

從目錄加載模塊

Modules loaded manually

使用IModuleManager手動加載模塊

ViewModelLocator

使用ViewModelLocator

ViewModelLocator - Change Convention

更改ViewModelLocator命名約定

ViewModelLocator - Custom Registrations

為特定視圖手動注冊ViewModels

DelegateCommand

使用DelegateCommand和DelegateCommand<T>

CompositeCommands

了解如何使用CompositeCommands作為單個命令調用多個命令

IActiveAware Commands

使您的命令IActiveAware僅調用激活的命令

Event Aggregator

使用IEventAggregator

Event Aggregator - Filter Events

訂閱事件時篩選事件

RegionContext

使用RegionContext將數據傳遞到嵌套區域

Region Navigation

請參見如何實現基本區域導航

Navigation Callback

導航完成后獲取通知

Navigation Participation

通過INavigationAware了解視圖和視圖模型導航參與

Navigate to existing Views

導航期間控制視圖實例

Passing Parameters

將參數從視圖/視圖模型傳遞到另一個視圖/視圖模型

Confirm/cancel Navigation

使用IConfirmNavigationReqest界面確認或取消導航

Controlling View lifetime

使用IRegionMemberLifetime自動從內存中刪除視圖

Navigation Journal

了解如何使用導航日志

部分項目演示和介紹

① BootstrapperShell啟動界面:

這個主要演示Prism框架搭建的用法:

step1:在nuget上引用Prsim.Unity。

step2:修改App.xaml:設置引導程序。

<Application x:Class="BootstrapperShell.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:BootstrapperShell">
<Application.Resources>

</Application.Resources>
</Application>
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);

var bootstrapper = new Bootstrapper();
bootstrapper.Run();
}
}

step3:在引導程序中設置啟動項目。

using Unity;
using Prism.Unity;
using BootstrapperShell.Views;
using System.Windows;
using Prism.Ioc;

namespace BootstrapperShell
{
class Bootstrapper : PrismBootstrapper
{
protected override DependencyObject CreateShell()
{
return Container.Resolve<MainWindow>();
}

protected override void RegisterTypes(IContainerRegistry containerRegistry)
{

}
}
}

step4:在MainWindow.xaml中顯示個字符串。

<Window x:Class="BootstrapperShell.Views.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Shell" Height="350" Width="525">
<Grid>
<ContentControl Content="Hello from Prism" />
</Grid>
</Window>

②ViewInjection:視圖注冊

MainWindow.xaml:通過ContentControl 關聯視圖:

<Window x:Class="ViewInjection.Views.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:prism="http://prismlibrary.com/"
Title="Shell" Height="350" Width="525">
<DockPanel LastChildFill="True">
<Button DockPanel.Dock="Top" Click="Button_Click">Add View</Button>
<ContentControl prism:RegionManager.RegionName="ContentRegion" />
</DockPanel>
</Window>

MainWindow.xaml.cs:鼠標點擊后通過IRegion 接口注冊視圖:

public partial class MainWindow : Window
{
IContainerExtension _container;
IRegionManager _regionManager;

public MainWindow(IContainerExtension container, IRegionManager regionManager)
{
InitializeComponent();
_container = container;
_regionManager = regionManager;
}

private void Button_Click(object sender, RoutedEventArgs e)
{
var view = _container.Resolve<ViewA>();
IRegion region = _regionManager.Regions["ContentRegion"];
region.Add(view);
}
}

③ActivationDeactivation:視圖激活和注銷

MainWindow.xaml.cs:這里在窗體構造函數中注入了一個容器擴展接口和一個regin管理器接口,分別用來裝載視圖和注冊regin,窗體的激活和去激活分別通過regions的Activate和Deactivate方法實現。

public partial class MainWindow : Window
{
IContainerExtension _container;
IRegionManager _regionManager;
IRegion _region;

ViewA _viewA;
ViewB _viewB;

public MainWindow(IContainerExtension container, IRegionManager regionManager)
{
InitializeComponent();
_container = container;
_regionManager = regionManager;

this.Loaded += MainWindow_Loaded;
}

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

_region = _regionManager.Regions["ContentRegion"];

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

private void Button_Click(object sender, RoutedEventArgs e)
{
//activate view a
_region.Activate(_viewA);
}

private void Button_Click_1(object sender, RoutedEventArgs e)
{
//deactivate view a
_region.Deactivate(_viewA);
}

private void Button_Click_2(object sender, RoutedEventArgs e)
{
//activate view b
_region.Activate(_viewB);
}

private void Button_Click_3(object sender, RoutedEventArgs e)
{
//deactivate view b
_region.Deactivate(_viewB);
}
}

④UsingEventAggregator:事件發布訂閱

事件類定義:

public class MessageSentEvent : PubSubEvent<string>
{
}

注冊兩個組件:ModuleA和ModuleB。

protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog)
{
moduleCatalog.AddModule<ModuleA.ModuleAModule>();
moduleCatalog.AddModule<ModuleB.ModuleBModule>();
}

ModuleAModule 中注冊視圖MessageView

public class ModuleAModule : IModule
{
public void OnInitialized(IContainerProvider containerProvider)
{
var regionManager = containerProvider.Resolve<IRegionManager>();
regionManager.RegisterViewWithRegion("LeftRegion", typeof(MessageView));
}

public void RegisterTypes(IContainerRegistry containerRegistry)
{

}
}

MessageView.xaml:視圖中給button俺妞妞綁定命令:

<UserControl x:Class="ModuleA.Views.MessageView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:prism="http://prismlibrary.com/"
prism:ViewModelLocator.AutoWireViewModel="True" Padding="25">
<StackPanel>
<TextBox Text="{Binding Message}" Margin="5"/>
<Button Command="{Binding SendMessageCommand}" Content="Send Message" Margin="5"/>
</StackPanel>
</UserControl>

MessageViewModel.cs:在vm中把界面綁定的命令委托給SendMessage,然后在方法SendMessage中發布消息:

using Prism.Commands;
using Prism.Events;
using Prism.Mvvm;
using UsingEventAggregator.Core;

namespace ModuleA.ViewModels
{
public class MessageViewModel : BindableBase
{
IEventAggregator _ea;

private string _message = "Message to Send";
public string Message
{
get { return _message; }
set { SetProperty(ref _message, value); }
}

public DelegateCommand SendMessageCommand { get; private set; }

public MessageViewModel(IEventAggregator ea)
{
_ea = ea;
SendMessageCommand = new DelegateCommand(SendMessage);
}

private void SendMessage()
{
_ea.GetEvent<MessageSentEvent>().Publish(Message);
}
}
}

在MessageListViewModel 中接收并顯示接收到的消息:

public class MessageListViewModel : BindableBase
{
IEventAggregator _ea;

private ObservableCollection<string> _messages;
public ObservableCollection<string> Messages
{
get { return _messages; }
set { SetProperty(ref _messages, value); }
}

public MessageListViewModel(IEventAggregator ea)
{
_ea = ea;
Messages = new ObservableCollection<string>();

_ea.GetEvent<MessageSentEvent>().Subscribe(MessageReceived);
}

private void MessageReceived(string message)
{
Messages.Add(message);
}
}

以上就是這個開源項目比較經典的幾個入門實例,其它就不展開講解了。


責任編輯:武曉燕 來源: dotNET編程大全
相關推薦

2020-03-26 10:33:36

工業互聯網概念

2020-03-26 10:25:26

工業互聯網IT工業物聯網

2020-03-27 15:49:17

工業物聯網技術5G

2025-01-06 06:10:00

開源.NEThttps://mp

2021-02-01 11:30:13

React前端調度

2021-03-23 10:25:05

Redis數據結構

2013-02-25 10:18:08

ThreadMsgC#

2009-08-26 15:25:06

.NET Framew

2023-11-13 07:54:54

.NET Core開源框架

2024-02-26 10:22:53

2023-10-26 00:30:00

Excel開源框架

2025-01-02 14:56:42

開源.NET開發

2024-06-05 08:17:37

C#算法數據科學

2023-10-20 14:36:08

開源軟件.Net開發

2024-12-19 08:58:50

2024-06-24 03:00:00

2024-10-15 17:12:38

代碼父子線程開源

2024-03-20 10:59:37

開源

2024-12-26 00:14:45

C#腳本開源

2015-07-29 10:00:16

開源項目
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 久久久国产一区二区三区四区小说 | 黄色大片在线视频 | 精品成人 | 天天夜干 | 欧美影院| 亚洲国产欧美91 | 精品久久久久久亚洲精品 | 精品免费视频 | 伊人在线视频 | 国内精品视频免费观看 | 色综合色综合网色综合 | 亚洲精品福利视频 | 精品视频一区二区三区 | 国产精品视频观看 | 国产一区二区三区四区在线观看 | 亚洲免费一区二区 | 国产精品久久久久久久久久久久久久 | 国产午夜精品一区二区三区四区 | 777777777亚洲妇女 | 国产做a爱片久久毛片 | 91av视频在线观看 | 青青艹在线视频 | 欧美一级黄色片免费观看 | 国产成人精品一区二区在线 | 中文字幕一区在线观看视频 | 国产综合精品一区二区三区 | 精品视频在线观看 | 亚洲福利 | 在线国产99| 国产精品国产精品国产专区不卡 | 久久精品中文字幕 | 精品国产一区二区三区久久久蜜月 | 久久亚洲天堂 | 亚洲啪啪 | 在线一级片 | 亚洲在线免费 | 国产一二三视频在线观看 | 日日干夜夜操 | 久久久久亚洲国产| 一区二区在线 | 性色视频 |