DevExpress 19.2.7 .NET Core 3.1 WPF程序开发及汉化

1. 下载并安装 DevExpres 19.2.7 Free 30-Days Trial

2. 下载汉化资源包 zh-Hans 19.2

3.  在Microsoft Visual Studio Community 2019中,创建新项目,选择“WPF App (.NET Core)”项目模板

4. 在资源管理器,项目“WpfApp1”点上鼠标右键,选择“管理 Nuget 程序包”

5. 在NuGet页面,程序包源切换到“DevExpress .NET Core Desktop 19.2 Local”。这时,可以看到第1步安装的DevExpress控件.

6.  以GridControl 为例,编写一个简单的WPF程序

6.1 在NuGet页面,输入"grid”搜索“DevExpress.WindowsDesktop.Wpf.Grid”,然后点“安装”

6.2 打开MainWindow.xmal设计器,在工具栏中选择GridControl,拖入到设计器中

6.3 编写代码

using System.Collections.Generic;
using System.Windows;

namespace WpfApp1
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            Students.AddRange(new[]
            {
                new Student { Name = "N1", Gender = "M", Age = 21 },
                new Student { Name = "N2", Gender = "F", Age = 20 }
            });

            DataContext = Students;
        }

         private List<Student> Students { get; } = new List<Student>();
    }

    public class Student
    {
        public string Name { get; set; }
        public string Gender { get; set; }
        public int Age { get; set; }
    }
}
<Window x:Class="WpfApp1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <dxg:GridControl ItemsSource="{Binding}">
            <dxg:GridControl.View>
                <dxg:TableView/>
            </dxg:GridControl.View>
            <dxg:GridColumn FieldName="Name"/>
            <dxg:GridColumn FieldName="Gender"/>
            <dxg:GridColumn FieldName="Age"/>
        </dxg:GridControl>
    </Grid>
</Window>

 6.3 添加 MetropolisLight 主题。先从项目NuGet窗口添加主题

然后,在App.xmal.cs中编写代码,加载主题

using DevExpress.Xpf.Core;
using System.Windows;

namespace WpfApp1
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {

        protected override void OnStartup(StartupEventArgs e)
        {
            // 使用 MetropolisLight 主题
            ApplicationThemeHelper.ApplicationThemeName = Theme.MetropolisLightName;
            
            base.OnStartup(e);
        }
    }
}

运行结果

7. 汉化 ,将下载好的zh-Hans 19.2资源文件,复制到运行目录

在App.xmal.cs中编写代码,加载汉化资源

using DevExpress.Xpf.Core;
using System.Windows;

namespace WpfApp1
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {

        protected override void OnStartup(StartupEventArgs e)
        {
            // 使用 MetropolisLight 主题
            ApplicationThemeHelper.ApplicationThemeName = Theme.MetropolisLightName;
            
            // 加载复制到运行文件夹中的汉化资源
            System.Runtime.Loader.AssemblyLoadContext.Default.Resolving += Default_Resolving;
            base.OnStartup(e);
        }

        private System.Reflection.Assembly Default_Resolving(System.Runtime.Loader.AssemblyLoadContext arg1, System.Reflection.AssemblyName arg2)
        {
            return null;
        }
    }
}

运行结果

 

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值