WPF如何开发Surface Dial

发布时间:2021-09-17 09:31:56 作者:小新
来源:亿速云 阅读:93

这篇文章主要介绍了WPF如何开发Surface Dial,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。

示例:

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

  [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】

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

2.MainWindow中代码

var interop = (IRadialControllerInterop)System.Runtime.InteropServices.WindowsRuntime.WindowsRuntimeMarshal
                .GetActivationFactory(typeof(RadialController));

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

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

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

感谢你能够认真阅读完这篇文章,希望小编分享的“WPF如何开发Surface Dial”这篇文章对大家有帮助,同时也希望大家多多支持亿速云,关注亿速云行业资讯频道,更多相关知识等着你来学习!

推荐阅读:
  1. 干货分享;Android开发之Activity的创建跳转及传值
  2. 仿途牛旅游APP项目开发

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

wpf

上一篇:MSDOS.SYS文件参数的设置方法

下一篇:asp.net core中异常处理与静态文件的示例分析

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》