日韩成人免费在线_国产成人一二_精品国产免费人成电影在线观..._日本一区二区三区久久久久久久久不

當前位置:首頁 > 科技  > 軟件

現(xiàn)代WPF界面輕松實現(xiàn):探秘輕量級WPFUI庫,MVVM與依賴注入一體化

來源: 責編: 時間:2024-03-26 09:34:27 204觀看
導讀概述:一款名為WPFUI的輕量級開源庫,為WPF應用程序提供現(xiàn)代化界面。支持MVVM和Microsoft.Extensions.DependencyInjection,簡單上手。無第三方依賴,內(nèi)置兩套皮膚,可自定義樣式。適用于一般應用場景,不受MVVM框架限制。通過簡

DQ028資訊網(wǎng)——每日最新資訊28at.com

概述:一款名為WPFUI的輕量級開源庫,為WPF應用程序提供現(xiàn)代化界面。支持MVVM和Microsoft.Extensions.DependencyInjection,簡單上手。無第三方依賴,內(nèi)置兩套皮膚,可自定義樣式。適用于一般應用場景,不受MVVM框架限制。通過簡單的引用和配置,快速構建現(xiàn)代化WPF應用,提升用戶體驗DQ028資訊網(wǎng)——每日最新資訊28at.com

最近要做個小工具軟件,發(fā)現(xiàn)以前用的WPF界面有點老了,所以在網(wǎng)上找下,發(fā)現(xiàn)一個用起來還可以的WPFUI庫,MVVM也支持得很好,同時支持微軟官方的依賴注入框架Microsoft.Extensions.DependencyInjection。DQ028資訊網(wǎng)——每日最新資訊28at.com

先來看看運行效果:DQ028資訊網(wǎng)——每日最新資訊28at.com

DQ028資訊網(wǎng)——每日最新資訊28at.com

使用方法也比較簡單。DQ028資訊網(wǎng)——每日最新資訊28at.com

1、引用庫:

DQ028資訊網(wǎng)——每日最新資訊28at.com

2、App.xaml引入資源

<Application    x:Class="DesktopApp.App"    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"    DispatcherUnhandledException="OnDispatcherUnhandledException"    Exit="OnExit"    Startup="OnStartup">    <Application.Resources>        <ResourceDictionary>            <ResourceDictionary.MergedDictionaries>                <ui:ThemesDictionary Theme="Dark" />                <ui:ControlsDictionary />            </ResourceDictionary.MergedDictionaries>        </ResourceDictionary>    </Application.Resources></Application>

3、App.xaml.cs注冊相關的Page、ViewModel、Service

public partial class App    {        // The.NET Generic Host provides dependency injection, configuration, logging, and other services.        // https://docs.microsoft.com/dotnet/core/extensions/generic-host        // https://docs.microsoft.com/dotnet/core/extensions/dependency-injection        // https://docs.microsoft.com/dotnet/core/extensions/configuration        // https://docs.microsoft.com/dotnet/core/extensions/logging        private static readonly IHost _host = Host            .CreateDefaultBuilder()            .ConfigureAppConfiguration(c => { c.SetBasePath(Path.GetDirectoryName(Assembly.GetEntryAssembly()!.Location)); })            .ConfigureServices((context, services) =>            {                services.AddHostedService<ApplicationHostService>();                services.AddSingleton<MainWindow>();                services.AddSingleton<MainWindowViewModel>();                services.AddSingleton<INavigationService, NavigationService>();                services.AddSingleton<ISnackbarService, SnackbarService>();                services.AddSingleton<IContentDialogService, ContentDialogService>();                services.AddSingleton<DashboardPage>();                services.AddSingleton<DashboardViewModel>();                services.AddSingleton<DataPage>();                services.AddSingleton<DataViewModel>();                services.AddSingleton<SettingsPage>();                services.AddSingleton<SettingsViewModel>();            }).Build();        /// <summary>        /// Gets registered service.        /// </summary>        /// <typeparam name="T">Type of the service to get.</typeparam>        /// <returns>Instance of the service or <see langword="null"/>.</returns>        public static T GetService<T>()            where T : class        {            return _host.Services.GetService(typeof(T)) as T;        }        /// <summary>        /// Occurs when the application is loading.        /// </summary>        private void OnStartup(object sender, StartupEventArgs e)        {            _host.Start();            Wpf.Ui.Appearance.Theme.Apply(Wpf.Ui.Appearance.ThemeType.Dark);        }        /// <summary>        /// Occurs when the application is closing.        /// </summary>        private async void OnExit(object sender, ExitEventArgs e)        {            await _host.StopAsync();            _host.Dispose();        }        /// <summary>        /// Occurs when an exception is thrown by an application but not handled.        /// </summary>        private void OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)        {            // For more info see https://docs.microsoft.com/en-us/dotnet/api/system.windows.application.dispatcherunhandledexception?view=windowsdesktop-6.0        }

4、MainWindow頁面進行主界面布局

這個代碼有點多就不粘了,文章結(jié)尾有源代碼下載,如果感興趣可以下載看看。DQ028資訊網(wǎng)——每日最新資訊28at.com

5、優(yōu)點

  • 這個庫包含了一些常用的控件沒有過多的封裝(輕量級),但足夠一般應用場景使用
  • 包含了兩套皮膚(如果不滿意可以自定義樣式個性色調(diào))
  • 沒有其它第三方的依賴,使用起來比較簡單
  • 使用官方Microsoft.Extensions.DependencyInjection作為依賴注入框架,也可以使用其他的
  • 沒有MVVM框架的限制,可以使用CommunityToolkit.Mvvm、Prism或其他的

再附上幾張效果圖:DQ028資訊網(wǎng)——每日最新資訊28at.com

DQ028資訊網(wǎng)——每日最新資訊28at.com

DQ028資訊網(wǎng)——每日最新資訊28at.com

DQ028資訊網(wǎng)——每日最新資訊28at.com

本文鏈接:http://www.www897cc.com/showinfo-26-79294-0.html現(xiàn)代WPF界面輕松實現(xiàn):探秘輕量級WPFUI庫,MVVM與依賴注入一體化

聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。郵件:2376512515@qq.com

上一篇: Python 集成測試: 提高軟件質(zhì)量的關鍵步驟

下一篇: 非Controller控制層參數(shù)校驗要怎么做

標簽:
  • 熱門焦點
Top 主站蜘蛛池模板: 丰宁| 昆明市| 南开区| 邯郸县| 华坪县| 金湖县| 临湘市| 舞阳县| 灌云县| 司法| 绵阳市| 扶沟县| 原平市| 花垣县| 曲水县| 中阳县| 镶黄旗| 新宾| 宣武区| 兰州市| 图片| 洮南市| 开封市| 邵阳市| 榕江县| 军事| 邮箱| 永顺县| 永嘉县| 尚义县| 东乌珠穆沁旗| 南溪县| 象州县| 遂昌县| 陈巴尔虎旗| 晋州市| 菏泽市| 黄平县| 隆化县| 同江市| 郁南县|