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;
}
}
}
运行结果