.NET8:快速集成Rapid.NET三维控件
.NET8正式版本发布了,AnyCAD Rapid.NET针对.NET8进行了升级和优化。本文以WPF项目为例介绍在.NET8中使用AnyCAD Rapid.NET三维控件。
1 从.NET6升级
若之前使用NET6升级到.NET8,升级过程非常简单,升级到AnyCAD Rapid .NET最新版本后,仅需要更改以下两处:
(1).csproj文件
1 | <TargetFramework>net8.0-windows</TargetFramework> |
(2)控件窗口
1 | xmlns:anycad= "clr-namespace:AnyCAD.WPF;assembly=AnyCAD.WPF.NET8" |
2 在.NET8项目中集成控件
对于新建的.NET8项目,使用AnyCAD Rapid .NET控件仅需要三步:
- 使用nuget安装控件
- 程序初始化
- 在XAML中使用控件
具体过程如下:
(1)安装Rapid .NET控件最新版本
(2)程序初始化
App.xaml
1 2 3 4 5 6 7 8 9 | <Application x:Class= "WpfStarter.App" xmlns= "http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x= "http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local= "clr-namespace:WpfStarter" StartupUri= "MainWindow.xaml" <strong>Startup= "Application_Startup" Exit= "Application_Exit" </strong>> <Application.Resources> </Application.Resources> </Application> |
App.xaml.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | using System.Windows; namespace WpfStarter { /// <summary> /// Interaction logic for App.xaml /// </summary> public partial class App : Application { private void Application_Startup( object sender, StartupEventArgs e) { <strong> AnyCAD.Foundation.GlobalInstance.Initialize();</strong> } private void Application_Exit( object sender, ExitEventArgs e) { <strong>AnyCAD.Foundation.GlobalInstance.Destroy();</strong> } } } |
(3) 窗口中添加三维控件
MainWindow.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <Window x:Class= "WpfStarter.MainWindow" xmlns= "http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x= "http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d= "http://schemas.microsoft.com/expression/blend/2008" xmlns:mc= "http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local= "clr-namespace:WpfStarter" <strong> xmlns:anycad= "clr-namespace:AnyCAD.WPF;assembly=AnyCAD.WPF.NET8" </strong> mc:Ignorable= "d" Title= "MainWindow" Height= "450" Width= "800" > <Grid> <Grid.ColumnDefinitions> <ColumnDefinition MinWidth= "100" Width= "0.3*" /> <ColumnDefinition/> </Grid.ColumnDefinitions> <strong> <anycad:RenderControl Grid.Column= "1" x:Name= "mRenderCtrl" Margin= "0,0,0,0" ViewerReady= "mRenderCtrl_ViewerReady" /></strong> </Grid> </Window> |
MainWindow.xaml.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | <strong> using AnyCAD.Foundation;</strong> using System.Collections.ObjectModel; using System.Linq; using System.Windows; namespace WpfStarter { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void mRenderCtrl_ViewerReady() { <strong> var shape = ShapeBuilder.MakeCylinder(GP.XOY(), 10, 20, 0); mRenderCtrl.ShowShape(shape, ColorTable.AliceBlue);</strong> } } } |
3 编译和运行项目
4 总结
.NET8带来了诸多新特性,建议还在使用.NET Framework 4.x的用户尽快升级。使用.NET6的用户升级到.NET8也是非常的丝滑~
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!