WPF 最基本的前后台代码对照
最基本的3D代码对照
xaml代码
<Viewport3D>
<Viewport3D.Camera>
<PerspectiveCamera Position="0, 0, 4"/>
</Viewport3D.Camera> <!-- Button on 3D -->
<Viewport2DVisual3D>
<!-- Give the plane a slight rotation -->
<Viewport2DVisual3D.Transform>
<RotateTransform3D>
<RotateTransform3D.Rotation>
<AxisAngleRotation3D Angle="" Axis="0, 1, 0" />
</RotateTransform3D.Rotation>
</RotateTransform3D>
</Viewport2DVisual3D.Transform> <!-- The Geometry, Material, and Visual for the Viewport2DVisual3D -->
<Viewport2DVisual3D.Geometry>
<MeshGeometry3D Positions="-1,1,0 -1,-1,0 1,-1,0 1,1,0"
TextureCoordinates="0,0 0,1 1,1 1,0" TriangleIndices="0 1 2 0 2 3"/>
</Viewport2DVisual3D.Geometry> <Viewport2DVisual3D.Material>
<DiffuseMaterial Viewport2DVisual3D.IsVisualHostMaterial="True" Brush="White"/>
</Viewport2DVisual3D.Material> <Button>Hello, 3D</Button>
</Viewport2DVisual3D> <!-- Lights -->
<ModelVisual3D>
<ModelVisual3D.Content>
<DirectionalLight Color="#FFFFFFFF" Direction="0,0,-1"/>
</ModelVisual3D.Content>
</ModelVisual3D>
</Viewport3D>
cs后台对照写法
private void Init_Draw()
{
Viewport3D viewport3D = new Viewport3D();
PerspectiveCamera perspectiveCamera = new PerspectiveCamera()
{
Position = new Point3D(, , ),
};
viewport3D.Camera = perspectiveCamera; Viewport2DVisual3D viewport2DVisual3D = new Viewport2DVisual3D();
RotateTransform3D rotateTransform3D = new RotateTransform3D();
AxisAngleRotation3D axisAngleRotation3D = new AxisAngleRotation3D()
{
Angle = ,
Axis = new Vector3D(, , ),
};
rotateTransform3D.Rotation = axisAngleRotation3D;
viewport2DVisual3D.Transform = rotateTransform3D; MeshGeometry3D meshGeometry3D = new MeshGeometry3D()
{
Positions = new Point3DCollection(new Point3D[] { new Point3D(-, , ), new Point3D(-, -, ), new Point3D(, -, ), new Point3D(, , ) }),
TextureCoordinates = new PointCollection { new Point(, ), new Point(, ), new Point(, ), new Point(, ) },
TriangleIndices = new Int32Collection(new int[] { , , , , , }),
};
viewport2DVisual3D.Geometry = meshGeometry3D; DiffuseMaterial diffuseMaterial = new DiffuseMaterial();
Viewport2DVisual3D.SetIsVisualHostMaterial(diffuseMaterial, true);
viewport2DVisual3D.Material = diffuseMaterial; Button button = new Button()
{
Content = "Hello,3D",
Direction = new Vector3D(0, 0, -1),
};
viewport2DVisual3D.Visual = button; ModelVisual3D modelVisual3D = new ModelVisual3D();
DirectionalLight directionalLight = new DirectionalLight()
{
Color = Color.FromRgb(, , ),
Direction = new Vector3D(0, 0, -1),
};
modelVisual3D.Content = directionalLight; viewport3D.Children.Add(viewport2DVisual3D);
viewport3D.Children.Add(modelVisual3D); Grid组件.Children.Add(viewport3D);
}
引伸一下,按照1:1大小显示原始组件,写入原始宽度和高度。显示出来的是原始UserControl的大小
private void Init_Draw(FrameworkElement element,double width,double height)
{
double Mesh_Width = width / ;
double Mesh_Height = height / ; Viewport3D viewport3D = new Viewport3D();
viewport3D.Width = width * ; PerspectiveCamera perspectiveCamera = new PerspectiveCamera();
double fieldOfViewInRadians = perspectiveCamera.FieldOfView * (Math.PI / 180.0);
var z = (0.5 * viewport3D.Width) / Math.Tan(0.5 * fieldOfViewInRadians);
perspectiveCamera.Position = new Point3D(, , z); perspectiveCamera.LookDirection = new Vector3D(, , -);
viewport3D.Camera = perspectiveCamera; Viewport2DVisual3D viewport2DVisual3D = new Viewport2DVisual3D();
RotateTransform3D rotateTransform3D = new RotateTransform3D();
axisAngleRotation3D = new AxisAngleRotation3D()
{
Angle = ,
Axis = new Vector3D(, , ),
};
rotateTransform3D.Rotation = axisAngleRotation3D;
viewport2DVisual3D.Transform = rotateTransform3D; MeshGeometry3D meshGeometry3D = new MeshGeometry3D()
{
Positions = new Point3DCollection(new Point3D[] {
new Point3D(-Mesh_Width, Mesh_Height, ),
new Point3D(-Mesh_Width, -Mesh_Height, ),
new Point3D(Mesh_Width, -Mesh_Height, ),
new Point3D(Mesh_Width, Mesh_Height, )
}
),
TextureCoordinates = new PointCollection { new Point(, ), new Point(, ), new Point(, ), new Point(, ) },
TriangleIndices = new Int32Collection(new int[] { , , , , , }),
};
viewport2DVisual3D.Geometry = meshGeometry3D; DiffuseMaterial diffuseMaterial = new DiffuseMaterial();
Viewport2DVisual3D.SetIsVisualHostMaterial(diffuseMaterial, true);
viewport2DVisual3D.Material = diffuseMaterial; viewport2DVisual3D.Visual = element;
element.MouseDown += Element_MouseDown; ModelVisual3D modelVisual3D = new ModelVisual3D();
DirectionalLight directionalLight = new DirectionalLight()
{
Color = Color.FromRgb(, , ),
Direction = new Vector3D(, , -),
};
modelVisual3D.Content = directionalLight; viewport3D.Children.Add(viewport2DVisual3D);
viewport3D.Children.Add(modelVisual3D); MainGrid.Children.Add(viewport3D);
}
WPF 最基本的前后台代码对照的更多相关文章
- 分页 工具类 前后台代码 Java JavaScript (ajax) 实现 讲解
[博客园cnblogs笔者m-yb原创, 转载请加本文博客链接,笔者github: https://github.com/mayangbo666,公众号aandb7,QQ群927113708]http ...
- FreeMarker中的list集合前后台代码
freemarker中的list集合前后台代码: FreeMarker是一款模板引擎: 即一种基于模板和要改变的数据, 并用来生成输出文本(HTML网页.电子邮件.配置文件.源代码等)的通用工具. 它 ...
- 示例:WPF中自定义StoryBoarService在代码中封装StoryBoard、Animation用于简化动画编写
原文:示例:WPF中自定义StoryBoarService在代码中封装StoryBoard.Animation用于简化动画编写 一.目的:通过对StoryBoard和Animation的封装来简化动画 ...
- 捕捉WPF应用程序中XAML代码解析异常
原文:捕捉WPF应用程序中XAML代码解析异常 由于WPF应用程序中XAML代码在很多时候是运行时加载处理的.比如DynamicResource,但是在编译或者运行的过程中,编写的XAML代码很可能有 ...
- WPF DataGrid分页功能实现代码
在Silverlight中DataGrid分页可以结合DataPager控件很容易实现,但是在WPF中没有类似的,需要手动实现这样一个控件: 1.创建一个UserControl,DP.xaml,代码如 ...
- WPF设计界面不执行代码
一般在我们在设计WPF XAML界面时,XAML 引用一些后端的类.比如UserControl.Converter.MVVM,引用 xmlns:ALLUserControl="clr-nam ...
- WPF/WP/Silverlight/Metro App代码创建动画的思路
在2010年之前,我都是用Blend创建动画,添加触发器实现自动动画,后来写成代码创建的方式.如今Blend已经集成到Visual Studio安装镜像中了,最新的VS2015安装,Blend的操作界 ...
- [WPF自定义控件库] 自定义控件的代码如何与ControlTemplate交互
1. 前言 WPF有一个灵活的UI框架,用户可以轻松地使用代码控制控件的外观.例设我需要一个控件在鼠标进入的时候背景变成蓝色,我可以用下面这段代码实现: protected override void ...
- 将Winform和wpf的界面转换为CPF代码用来实现跨平台
CPF的设计器里带界面代码转换功能,将运行中的Winform或者wpf的程序界面转换为cpf代码,主要转换控件类型和布局,默认支持的是常用的原生控件.不支持Netcore,只支持.Netframewo ...
随机推荐
- Spring WebFlux 学习笔记 - (一) 前传:学习Java 8 Stream Api (3) - Stream的终端操作
Stream API Java8中有两大最为重要的改变:第一个是 Lambda 表达式:另外一个则是 Stream API(java.util.stream.*). Stream 是 Java8 中处 ...
- PIP 更换国内安装源
linux: 修改 ~/.pip/pip.conf (没有就创建一个), 内容如下: [global] index-url = https://pypi.tuna.tsinghua.edu.cn/si ...
- SpringBoot 中注解方式的拦截过滤
使用场景 公司运行的App 登陆-验证码短信接口,遭到大量的恶意攻击.处于安全的考虑,需要客户端api目前的一些接口加上验证签名的功能,以提高安全性. 现行的App之前也有过签名的秘钥在,后来出于性能 ...
- @loj - 3120@ 「CTS2019 | CTSC2019」珍珠
目录 @description@ @solution@ @accepted code@ @details@ @description@ 有 \(n\) 个在范围 \([1, D]\) 内的整数均匀随机 ...
- CentOS7.5搭建Kafka2.11-1.1.0集群与简单测试
一.下载 下载地址: http://kafka.apache.org/downloads.html 我这里下载的是Scala 2.11对应的 kafka_2.11-1.1.0.tgz 二.集群规 ...
- 附016.Kubernetes_v1.17.4高可用部署
一 kubeadm介绍 1.1 概述 参考<附003.Kubeadm部署Kubernetes>. 1.2 kubeadm功能 参考<附003.Kubeadm部署Kubernetes& ...
- 项目实战:Qt手机模拟器拉伸旋转框架
若该文为原创文章,未经允许不得转载原博主博客地址:https://blog.csdn.net/qq21497936原博主博客导航:https://blog.csdn.net/qq21497936/ar ...
- Oracel中coalesce函数的用法
1.coalesce函数的用法 1.1 取出第一个不为空的列的数据.
- 用Creator实现一个擀面的效果
先上几张效果图 怎么实现的呢? 节点介绍 1是背景图,可以忽略:2 是准备好的面团:3 是擀好的面饼先隐藏:4 是需要绘制的节点:5 是擀面杖. 制作开始 首先在view上挂一个mask,并且设置为模 ...
- 3分钟理解NMS非极大值抑制
1. NMS被广泛用到目标检测技术中,正如字面意思,抑制那些分数低的目标,使最终框的位置更准: 2. 假如图片上实际有10张人脸,但目标检测过程中,检测到有30个框的位置,并且模型都认为它们是人脸,造 ...