.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" Startup="Application_Startup" Exit="Application_Exit"

    <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)

        {

           AnyCAD.Foundation.GlobalInstance.Initialize();

        }

        private void Application_Exit(object sender, ExitEventArgs e)

        {

            AnyCAD.Foundation.GlobalInstance.Destroy();

        }

    }

}

  

(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"

          xmlns:anycad="clr-namespace:AnyCAD.WPF;assembly=AnyCAD.WPF.NET8"

        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

using AnyCAD.Foundation;

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()

        {

            var shape = ShapeBuilder.MakeCylinder(GP.XOY(), 10, 20, 0);

            mRenderCtrl.ShowShape(shape, ColorTable.AliceBlue);

        }

    }

}

  

3 编译和运行项目

4 总结

.NET8带来了诸多新特性,建议还在使用.NET Framework 4.x的用户尽快升级。使用.NET6的用户升级到.NET8也是非常的丝滑~

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值