WPF旋转的界面实现
原文:WPF旋转的界面实现
在WPF中可以做出旋转的界面,这样不仅效果好看,而且节省界面和代码处理。
xaml代码如下:
<Window x:Class="V3ViewApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Title="旋转界面" Height="360" Width="450" Background="Black" WindowState="Normal" WindowStartupLocation="CenterScreen">
<Window.Resources>
<sys:Double x:Key="grdSize">200</sys:Double>
</Window.Resources>
<Grid >
<Viewport3D ClipToBounds="True" HorizontalAlignment="Center" VerticalAlignment="Center" Height="500" Width="500">
<Viewport3D.Camera>
<PerspectiveCamera LookDirection="0,0,-1" Position="0,0,300"/>
</Viewport3D.Camera>
<Viewport3D.Children>
<ModelVisual3D>
<ModelVisual3D.Content>
<AmbientLight Color="Transparent"/>
</ModelVisual3D.Content>
<ModelVisual3D.Children>
<Viewport2DVisual3D>
<Viewport2DVisual3D.Geometry>
<MeshGeometry3D Positions="-50,50,-50 -50,-50,-50 -50,-50,50 -50,50,50"
Normals="0,0,1 0,0,1 0,0,1 0,0,1"
TriangleIndices="0,1,2 0,2,3"
TextureCoordinates="0,0 0,1 1,1 1,0"/>
</Viewport2DVisual3D.Geometry>
<Viewport2DVisual3D.Material>
<DiffuseMaterial Brush="Transparent" Viewport2DVisual3D.IsVisualHostMaterial="True"/>
</Viewport2DVisual3D.Material>
<Viewport2DVisual3D.Visual>
<Grid Background="Yellow" Width="{StaticResource grdSize}" Height="{StaticResource grdSize}">
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
</Grid>
</Viewport2DVisual3D.Visual>
</Viewport2DVisual3D>
<Viewport2DVisual3D>
<Viewport2DVisual3D.Geometry>
<MeshGeometry3D Positions="-50,50,50 -50,-50,50 50,-50,50 50,50,50"
Normals="0,0,1 0,0,1 0,0,1 0,0,1"
TriangleIndices="0,1,2 0,2,3"
TextureCoordinates="0,0 0,1 1,1 1,0"/>
</Viewport2DVisual3D.Geometry>
<Viewport2DVisual3D.Material>
<DiffuseMaterial Brush="Transparent" Viewport2DVisual3D.IsVisualHostMaterial="True"/>
</Viewport2DVisual3D.Material>
<Viewport2DVisual3D.Visual>
<Grid Background="Red" Height="{StaticResource grdSize}" Width="{StaticResource grdSize}">
<StackPanel Margin="4">
</StackPanel>
</Grid>
</Viewport2DVisual3D.Visual>
</Viewport2DVisual3D>
<Viewport2DVisual3D>
<Viewport2DVisual3D.Geometry>
<MeshGeometry3D Positions="50,50,50 50,-50,50 50,-50,-50 50,50,-50"
Normals="0,0,1 0,0,1 0,0,1 0,0,1"
TriangleIndices="0,1,2 0,2,3"
TextureCoordinates="0,0 0,1 1,1 1,0"/>
</Viewport2DVisual3D.Geometry>
<Viewport2DVisual3D.Material>
<DiffuseMaterial Brush="Transparent" Viewport2DVisual3D.IsVisualHostMaterial="True"/>
</Viewport2DVisual3D.Material>
<Viewport2DVisual3D.Visual>
<Grid Background="Green" Width="{StaticResource grdSize}" Height="{StaticResource grdSize}">
<Canvas>
<Ellipse />
</Canvas>
</Grid>
</Viewport2DVisual3D.Visual>
</Viewport2DVisual3D>
<Viewport2DVisual3D>
<Viewport2DVisual3D.Geometry>
<MeshGeometry3D Positions="50,50,-50 50,-50,-50 -50,-50,-50 -50,50,-50"
Normals="0,0,1 0,0,1 0,0,1 0,0,1"
TriangleIndices="0,1,2 0,2,3"
TextureCoordinates="0,0 0,1 1,1 1,0"/>
</Viewport2DVisual3D.Geometry>
<Viewport2DVisual3D.Material>
<DiffuseMaterial Brush="Transparent" Viewport2DVisual3D.IsVisualHostMaterial="True"/>
</Viewport2DVisual3D.Material>
<Viewport2DVisual3D.Visual>
<Grid Background="Blue" Height="{StaticResource grdSize}" Width="{StaticResource grdSize}">
</Grid>
</Viewport2DVisual3D.Visual>
</Viewport2DVisual3D>
</ModelVisual3D.Children>
<ModelVisual3D.Transform>
<RotateTransform3D CenterX="0" CenterY="0" CenterZ="0">
<RotateTransform3D.Rotation>
<AxisAngleRotation3D Angle="0" Axis="0,1,0" x:Name="ar"/>
</RotateTransform3D.Rotation>
</RotateTransform3D>
</ModelVisual3D.Transform>
</ModelVisual3D>
</Viewport3D.Children>
</Viewport3D>
</Grid>
</Window>
CS代码如下:
public MainWindow()
{
InitializeComponent();
// 设置快捷键
KeyBinding forwBind = new System.Windows.Input.KeyBinding();
forwBind.Command = new ForwCommand();
forwBind.CommandParameter = ar;
forwBind.Key = System.Windows.Input.Key.Right;
this.InputBindings.Add(forwBind);
KeyBinding backBind = new System.Windows.Input.KeyBinding();
backBind.Command = new BackCommand();
backBind.CommandParameter = ar;
backBind.Key = System.Windows.Input.Key.Left;
this.InputBindings.Add(backBind);
this.Loaded += (k, k2) =>
{
};
}
}
/// <summary>
/// 向前移动
/// </summary>
public class ForwCommand : ICommand
{
public bool CanExecute(object parameter)
{
if (parameter == null)
{
return false;
}
return true;
}
public event EventHandler CanExecuteChanged;
public void Execute(object parameter)
{
AxisAngleRotation3D rot = parameter as AxisAngleRotation3D;
DoubleAnimation d = new DoubleAnimation();
d.Duration = new Duration(TimeSpan.FromMilliseconds(800));
d.By = 90d;
rot.BeginAnimation(AxisAngleRotation3D.AngleProperty, d, HandoffBehavior.Compose);
}
}
/// <summary>
/// 向后移动
/// </summary>
public class BackCommand : ICommand
{
public bool CanExecute(object parameter)
{
if (parameter == null)
{
return false;
}
return true;
}
public event EventHandler CanExecuteChanged;
public void Execute(object parameter)
{
AxisAngleRotation3D rot = parameter as AxisAngleRotation3D;
DoubleAnimation d = new DoubleAnimation();
d.By = -90d;
d.Duration = new Duration(TimeSpan.FromMilliseconds(800));
rot.BeginAnimation(AxisAngleRotation3D.AngleProperty, d, HandoffBehavior.Compose);
}
}
最后用键盘左右键实现界面切换,之后可以自己改成别的快捷键进行切换。
效果如图:
WPF旋转的界面实现的更多相关文章
- Wix 安装部署教程(九) --用WPF做安装界面
经常安装PC端的应用,特别是重装系统之后,大致分为两类.一类像QQ,搜狗输入法这样的.分三步走的:第一个页面可以自定义安装路径和软件许可.第二个页面显示安装进度条,第三个页面推荐其他应用.先不管人家怎 ...
- WPF模拟雷达界面效果图
原文:WPF模拟雷达界面效果图 iPad塔防的防守兵的效果很炫,2个小时用WPF模拟了一个. 效果图: 关键代码: <Grid> <Grid.Background> <I ...
- wpf中防止界面卡死的写法
原文:wpf中防止界面卡死的写法 ); this.Dispatcher.BeginInvoke(new Action(() => { this.button1.Content = "计 ...
- C# WPF 一个设计界面
微信公众号:Dotnet9,网站:Dotnet9,问题或建议:请网站留言, 如果对您有所帮助:欢迎赞赏. C# WPF 一个设计界面 今天正月初三,大家在家呆着挺好,不要忘了自我充电. 武汉人民加油, ...
- WPF 显示初始化界面
今天在看<WPF编程宝典>时,看到了Application类,该类可以做很多事情,我认为比较实用的是显示初始化界面,因为之前有个项目在打开的时候要加载好多dll,非常耗时,让客户等的蛋疼, ...
- WPF设置软件界面背景为MediaElement并播放视频
在我们的常见的软件界面设计中我们经常会设置软件的背景为SolidColorBrush或者LinerColorBrush.RadialGradientBrush 等一系列的颜色画刷为背景,有时我们也会使 ...
- WPF开发的界面调用C++生成的dll文件
以引用d1.dll为例. [生成d1.dll] 文件——新建——项目——Visual C++——Win32项目,选择DLL,点击Finish.在d1.cpp中添加代码 #include "s ...
- 【WPF/WAF】界面布局(View)文件的多层嵌套(Nest)
碎碎念:使用的是略冷门的Window Application Foundation(WAF)框架,搜到的都是WPF的UserControl用户控件的用法,实在蛋疼. 需求:主界面ShellWindow ...
- [WPF]绑定到界面的数组不支持调度线程以外对其更改的办法
[原]WPF编程经常遇到一个问题: 某个数组己绑定到主界面某控件中,然后在后台程序中需要对数组增(减)数据,然后程序就会报错, 程序提示:该类型的CollectionView 不支持从调度程序线程以外 ...
随机推荐
- Fragment为载体可自己主动布局的CardView(GitHub上写开源项目初体验)
转载请注明本文出自大苞米的博客(http://blog.csdn.net/a396901990),谢谢支持! 开篇废话: 前些天一直在看Android5.0 的Material Desgin,里面新增 ...
- [Angular2 Form] Create custom form component using Control Value Accessor
//switch-control component import { Component } from '@angular/core'; import { ControlValueAccessor, ...
- JVM调优基础 分类: B1_JAVA 2015-03-14 09:33 250人阅读 评论(0) 收藏
一.JVM调优基本流程 1.划分应用程序的系统需求优先级 2.选择JVM部署模式:单JVM.多JVM 3.选择JVM运行模式 4.调优应用程序内存使用 5.调优应用程序延迟 6.调优应用程序吞吐量 二 ...
- js 99乘法表
哈哈哈,笑死我了,突然怀念学习时代,撸了一个乘法表 for(let a=1;a<10;a++){let str = ''; for(let b=1;b<10;b++){ str = str ...
- WebService--概述、JDk实现、AJAX调用
一.Webservice概述 W3C组织对其的定义是,它是一个软件系统,为了支持跨网络的机器间相互操作交互而设计. Webservice服务通常被定义为一组模块化的API,它们可以通过网络进行调用,来 ...
- FAST特征点检测&&KeyPoint类
FAST特征点检测算法由E.Rosten和T.Drummond在2006年在其论文"Machine Learning for High-speed Corner Detection" ...
- 【C++竞赛 A】xxx的项链
时间限制:2s 内存限制:64MB 问题描述 xxx有一个长度为n的宝石链,宝石有m种不同的颜色.xxx想截取其中连续的一段做一个项链.为了让项链更漂亮,xxx希望项链中的宝石包含所有颜色. 输入描述 ...
- jquery-5 jQuery筛选选择器
jquery-5 jQuery筛选选择器 一.总结 一句话总结:选择器加动态添加方法可以不用想方法名,这个简单方便. 1.筛选选择器有哪三种? 过滤 查找 串联 1.过滤 eq();first(); ...
- 【转】request和response的页面跳转
跳转:request.getRequestDispatcher("p3.jsp").forward(request,response);这种方法称为转发,地址栏上的URL不会改变: ...
- GlobalMemoryStatus 和 GlobalMemoryStatusEx
1.获取系统内存信息有2个api,分别是GlobalMemoryStatus和GlobalMemoryStatusEx.GlobalMemoryStatus函数可以在C语言里直接调用,但是Global ...