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 ...
随机推荐
- gitee+picgo搭建个人博客图床
gitee+picgo搭建个人博客图床 准备 首先需要去码云注册一个账号,并新建一个仓库.接着下载PicGO并安装好. 过程 点击左下方的插件设置. image 在搜索框中输入gitee搜索插件,安装 ...
- 数据误操作,删库跑路?教你使用ApexSQLLog工具从 SQLServer日志恢复数据!
前几天同事不小心误操作,将SQLServer库的一张表的一个状态字段给刷成了一个统一状态,由于是update执行所以原来的相关状态无法确定.发生这种事情的时候我的小伙伴背后 一凉,估计心里里面想这怕是 ...
- PAT1040 Longest Symmetric String (25分) 中心扩展法+动态规划
题目 Given a string, you are supposed to output the length of the longest symmetric sub-string. For ex ...
- 五个Taurus垃圾回收compactor优化方案,减少系统资源占用
简介 TaurusDB是一种基于MySQL的计算与存储分离架构的云原生数据库,一个集群中包含多个存储几点,每个存储节点包含多块磁盘,每块磁盘对应一个或者多个slicestore的内存逻辑结构来管理. ...
- excel筛选重复项代码
Sub test()'updateby Extendoffice 20151030 Dim xRng As Range Dim xTxt As String On Error Res ...
- PN532资料 NFC RFID V3模块
最新PN532链接: https://pan.baidu.com/s/1HyXk-VuF-24ZJ8zAVb9lcA 提取码: bgju 复制这段内容后打开百度网盘手机App,操作更方便哦
- 我从LongAdder中窥探到了高并发的秘籍,上面只写了两个字...
这是why的第 53 篇原创文章 荒腔走板 大家好,我是why. 时间过的真是快,一周又要结束了.那么,你比上周更博学了吗?先来一个简短的荒腔走板,给冰冷的技术文注入一丝色彩. 上面这图是我之前拼的一 ...
- 图解leetcode5-10 | 和233酱一起刷leetcode系列(2)
本周我们继续来看5道磨人的小妖精,图解leetcode6-10- 多说一句,leetcode10 杀死了233酱不少脑细胞... 另: 沉迷算法,无法自拔.快来加入我们吧! 别忘了233酱的一条龙服务 ...
- JavaWeb网上图书商城完整项目--day02-24.分类模块的相关类创建
所谓的分类模块:就是显示所有的分类的功能,显示所有的分类在left.jsp页面中 这就是显示所有的分类: 要实现上面的,我们首先创建一个分类模块,该模块需要实现下面的功能 我们先创建上面的java包 ...
- 内存节省机制C演示
编写代码实质是通过指令对计算机内存进行操作,计算机的硬件设备往往十分有限,尤其是内存.如何使有限的存储空间利用效率达到最大,成为了代码优化首先要考虑的事情. 比如,输入三个数比较大小并输出最小值.下面 ...