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

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

開發 后端
最近要做個小工具軟件,發現以前用的WPF界面有點老了,所以在網上找下,發現一個用起來還可以的WPFUI庫,MVVM也支持得很好,同時支持微軟官方的依賴注入框架Microsoft.Extensions.DependencyInjection。

概述:一款名為WPFUI的輕量級開源庫,為WPF應用程序提供現代化界面。支持MVVM和Microsoft.Extensions.DependencyInjection,簡單上手。無第三方依賴,內置兩套皮膚,可自定義樣式。適用于一般應用場景,不受MVVM框架限制。通過簡單的引用和配置,快速構建現代化WPF應用,提升用戶體驗

最近要做個小工具軟件,發現以前用的WPF界面有點老了,所以在網上找下,發現一個用起來還可以的WPFUI庫,MVVM也支持得很好,同時支持微軟官方的依賴注入框架Microsoft.Extensions.DependencyInjection。

先來看看運行效果:

使用方法也比較簡單。

1、引用庫:

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頁面進行主界面布局

這個代碼有點多就不粘了,文章結尾有源代碼下載,如果感興趣可以下載看看。

5、優點

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

再附上幾張效果圖:

責任編輯:姜華 來源: 今日頭條
相關推薦

2025-05-13 09:23:24

2009-09-07 23:09:17

2023-11-16 13:24:39

OceanBase數據庫

2023-12-20 07:35:03

大模型數據治理機器學習

2024-01-02 08:22:01

Koin框架項目

2011-05-24 09:26:02

有線無線3G

2009-08-17 22:32:25

IT運維管理監控運維一體化摩卡

2009-07-02 09:32:00

2009-12-03 15:34:41

Suse Linux

2020-04-24 11:13:50

物聯網智慧社區技術

2014-10-14 10:45:18

用友

2023-07-19 22:13:25

一體化推送平臺

2009-03-19 09:50:00

華為機房一體化

2017-05-16 10:46:06

博陽咨詢流程管理

2014-12-25 11:25:31

2009-02-06 14:12:00

數據中心機房

2013-11-08 18:01:43

SAP中國商業同略會

2014-11-06 10:31:55

移動營銷
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 不卡欧美 | 9999国产精品欧美久久久久久 | 国产一区二区自拍 | 久久久久久免费精品一区二区三区 | 一区二区在线不卡 | 日韩一二区 | 亚洲啪啪 | 久久久久久久久91 | 手机日韩 | 性国产丰满麻豆videosex | av一区在线观看 | www.激情.com | 亚洲国产精品一区二区三区 | 久久福利电影 | wwwsihu| 久久久久久99 | 日韩精品成人网 | 亚洲久久在线 | 欧美国产日韩在线观看 | 日韩有码一区 | 蜜臀久久99精品久久久久野外 | 日韩免费福利视频 | 国产电影一区 | 91一区二区三区 | 91久久精品国产 | 日韩av在线中文字幕 | 一区精品在线观看 | 久久久999精品 | 欧美日韩一区二区三区四区 | 91看片网址| 亚洲成人一区二区三区 | 在线看黄免费 | 91精品国产综合久久久久久漫画 | 一级毛片免费 | 国产高清一二三区 | 九九九视频在线观看 | 一级做a爰片性色毛片16美国 | 中文字幕在线二区 | 亚洲国产一区二区三区 | 91精品国产91久久久久久吃药 | 欧美激情视频一区二区三区在线播放 |