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 ...
随机推荐
- 诸葛亮vs司马懿,排序算法大战谁能笑到最后?
阵前对峙 公元234年,蜀汉丞相诸葛孔明再次北伐. 一日,与司马仲达所率魏军两军相峙,二人阵前舌战. 司马曰:"诸葛村夫,吾与汝相斗数年,斗兵斗阵斗谋略,均已疲乏.今日,何不一改陈规,斗点新 ...
- CentOS7 yum 安装配置 MySQL 5.7
1.配置yum源 # 下载mysql源安装包 wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm # 安装 ...
- 别让HR再质问我:我费劲招的人,你用缓存问废了,不能简单点?
概念 缓存穿透 在高并发下,查询一个不存在的值时,缓存不会被命中,导致大量请求直接落到数据库上,如活动系统里面查询一个不存在的活动. 缓存击穿 在高并发下,对一个特定的值进行查询,但是这个时候缓存正好 ...
- kafka能做什么?kafka集群配置 (卡夫卡 大数据)
什么是Kafka 官网介绍: 几个概念: 详细介绍 : 操作kafka: kafka集群 消息测试 问题检测 什么是Kafka 官网介绍: ApacheKafka是一个分布式流媒体平台.这到底是什么意 ...
- [web][学习随笔]php中http post&get数据传输
GET <!--客户端发送--> <form id="form1" action="doGet.php" method="get&q ...
- 君荣 TS--8200 消费机显示说明
Err 001——不在消费时段内Err 002——非本系统卡Err 003——余额不足Err 004——级别未开放Err 005——卡已挂失Err 006——有效期未生效Err 007——已过有效期 ...
- Xor Sum(讲解异或)【字典树】
Xor Sum 题目链接(点击) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 132768/132768 K (Java/Other ...
- 2019-02-02 Python学习之死锁和Rlock
死锁:"当一个线程永远地持有一个锁,并且其他线程都尝试去获得这个锁时,那么它们将永远被阻塞" e.g. import threading import time mutexboy ...
- Mysql事务 JAVAGC 面试
忽略其他问题,直接上技术面试 你们公司服务器中配置Java GC是哪一种? Java GC 一共分为四种,分别是 -XX:+UseSerialGC 串行垃圾回收器 -XX:+UseParallelGC ...
- opencv c++访问某一区域
int main(){ cv::Mat m1(,, CV_8UC1); for(int i=;i<m1.rows;++i) for(int j=;j<m1.cols;++j) m1.at& ...