WPF开发Surface Dial实例教程


本文摘自PHP中文网,作者零下一度,侵删。

前段时间巨硬发布了一款新的输入设备Surface Dial,配合Surface Studio使用简直炫酷到没朋友。

本人由于公司业务有幸参与了微软的相关培训,最大的收获觉得是发现WPF居然也可以开发Dial, WPF居然可以使用UWP的API!

不卖关子,关键就是名为“UwpDesktop”的一个Nuget,在我们的WPF程序中添加这个nuget就可以了。上一篇文章中写的WPF起调UWP也借助了这个nuget。

由于我们的现有解决方案是拿wpf做的,所以培新间歇我直奔主题,就问老外这个东西滋不滋磁WPF,得到的答案是肯定的。那怎么用呢,有没有demo呢,还真有,那再麻烦您拷给我吧,,,于是有了下面的demo

我还是直接贴代码吧,

1

2

3

4

5

6

7

8

9

10

11

public MainWindow()

        {

            InitializeComponent();//SetRadialControllerConfiguration();var interop = (IRadialControllerInterop)System.Runtime.InteropServices.WindowsRuntime.WindowsRuntimeMarshal

                .GetActivationFactory(typeof(RadialController));

 

            Guid guid = typeof(RadialController).GetInterface("IRadialController").GUID;

 

            Window window = Window.GetWindow(this);var wih = new WindowInteropHelper(window);

            IntPtr hWnd = wih.Handle;// Create a reference to the RadialController.radialController = interop.CreateForWindow(hWnd, ref guid);string iconFileName = "Assets\\dial_icon_custom_item.png";string filePath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, iconFileName);var getItemImageOperation = StorageFile.GetFileFromPathAsync(filePath);

            getItemImageOperation.Completed += new AsyncOperationCompletedHandler<StorageFile>(AddMenuItemFromImage);// Declare input handlers for the RadialController.radialController.RotationChanged += RadialController_RotationChanged; ;

        }

还有个很关键的类RadialControllerInterfaces.cs

1

2

3

4

5

6

7

8

9

10

11

[System.Runtime.InteropServices.Guid("787cdaac-3186-476d-87e4-b9374a7b9970")]

  [System.Runtime.InteropServices.InterfaceType(System.Runtime.InteropServices.ComInterfaceType.InterfaceIsIInspectable)]interface IRadialControllerConfigurationInterop

  {

      RadialControllerConfiguration GetForWindow(IntPtr hwnd, [System.Runtime.InteropServices.In]ref Guid riid);

  }

 

  [System.Runtime.InteropServices.Guid("1B0535C9-57AD-45C1-9D79-AD5C34360513")]

  [System.Runtime.InteropServices.InterfaceType(System.Runtime.InteropServices.ComInterfaceType.InterfaceIsIInspectable)]interface IRadialControllerInterop

  {

      RadialController CreateForWindow(IntPtr hwnd, [System.Runtime.InteropServices.In]ref Guid riid);

  }

这个类提供了CreateForWindow方法可以让我们创建RadialController对象,个人觉得这个接口很玄乎,上边的Guid特性(这个是叫特性吧?)是写死的,问了工程师说这个不用改,这不就很坑了,如果不是有个demo,我怎么知道怎么写,,,

作为弱鸡,这里我也有问题请教大家:

1.这些特性的作用,平时自己写代码貌似只用过【datacontract】

1

<br>

1

2

[System.Runtime.InteropServices.Guid("1B0535C9-57AD-45C1-9D79-AD5C34360513")]

[System.Runtime.InteropServices.InterfaceType(System.Runtime.InteropServices.ComInterfaceType.InterfaceIsIInspectable)]    

2.MainWindow中代码

1

2

var interop = (IRadialControllerInterop)System.Runtime.InteropServices.WindowsRuntime.WindowsRuntimeMarshal

                .GetActivationFactory(typeof(RadialController));

总觉得阅读性这么差呢,看不懂,或许是我从未见过,对这个方法不熟?

微软工程师给我的这个Demo我发现有两个Bug(他本人也表示还没写完,是Dirty Demo),一个是SetRadialControllerConfiguration这个方法里异常,不能用,导致不能初始化Dial的菜单,每次启动应用都会往菜单里

添加一项;另一个是焦点问题,当长按dial选择了其他菜单,例如音量,再返回我们的demo,发现此时dial仍然控制的是音量

由于本人太弱,就不多说了,末尾附上Dr.Neil的demo大家自己研究下,也希望大家留言评论解答我的疑惑

链接: 密码: h722

1

<br><br>

以上就是WPF开发Surface Dial实例教程的详细内容!

相关阅读 >>

对asp.net中的mvc引擎开发插系统进行详解

c#开发微信门户及应用(二)之微信消息处理和应答的图文代码教程

wpf开发surface dial实例教程

.net core + angular cli 实现开发环境搭建

c#开发微信门户及应用(一)之微信接口的如何使用(图)

分享一个“网红脸“”框架实例教程

c#开发中遇到的问题分享

基于mvc5中的model层开发数据注解_实用技巧

介绍一个力软敏捷开发框架

c#开发微信门户及应用(三)之文本消息和图文消息应答

更多相关阅读请进入《UwpDesktop》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...