Original: uwpdesktop! WPF can also develop surface Dial
Some time ago, the giant hard released a new input device surface Dial, with surface studio used to be simply cool to no friends.
I was fortunate to be involved in the company's business training, the biggest harvest is to discover that WPF can also develop dial, WPF can actually use the UWP api!
Not suspense, the key is a nuget named "Uwpdesktop", which adds this nuget to our WPF program. The WPF tuning UWP that was written in the previous article also took advantage of this nuget.
Since our existing solution is to take WPF, so the new intermittent I go straight to the topic, asked the foreigner this thing aids magnetic WPF, the answer is yes. How to use it, there is no demo, there is really, then trouble you copy to me,,, and then have the following demo
I'll just stick to the code.
PublicMainWindow () {InitializeComponent (); //setradialcontrollerconfiguration (); varInterop =(Iradialcontrollerinterop) System.Runtime.InteropServices.WindowsRuntime.WindowsRuntimeMarshal. Getactivationfactory (typeof(Radialcontroller)); GUID GUID=typeof(Radialcontroller). GetInterface ("Iradialcontroller"). GUID; Window Window= Window.getwindow ( This); varwih =Newwindowinterophelper (window); INTPTR hWnd=wih. Handle; //Create A reference to the Radialcontroller.Radialcontroller = Interop. Createforwindow (HWnd,refGUID); stringIconFileName ="Assets\\dial_icon_custom_item.png"; stringFilePath =System.IO.Path.Combine (AppDomain.CurrentDomain.BaseDirectory, iconFileName); varGetitemimageoperation =Storagefile.getfilefrompathasync (FilePath); Getitemimageoperation.completed+=NewAsyncoperationcompletedhandler<storagefile>(Addmenuitemfromimage); //Declare input handlers for the Radialcontroller.Radialcontroller.rotationchanged + =radialcontroller_rotationchanged;; }
And there's a very critical class RadialControllerInterfaces.cs.
[System.Runtime.InteropServices.Guid ("787cdaac-3186-476d-87e4-b9374a7b9970")] [System.Runtime.InteropServices.InterfaceType ( System.Runtime.InteropServices.ComInterfaceType.InterfaceIsIInspectable)]InterfaceIradialcontrollerconfigurationinterop {radialcontrollerconfiguration Getforwindow (IntPtr hwnd, [System.Run Time. Interopservices.in]refGuid riid); } [System.Runtime.InteropServices.Guid ("1b0535c9-57ad-45c1-9d79-ad5c34360513")] [System.Runtime.InteropServices.InterfaceType ( System.Runtime.InteropServices.ComInterfaceType.InterfaceIsIInspectable)]InterfaceIradialcontrollerinterop {radialcontroller Createforwindow (IntPtr hwnd, [System.Runtime.InteropServices.In ]refGuid riid); }
This class provides a Createforwindow method that allows us to create Radialcontroller objects, which the individual feels is iffy, the top GUID feature (this is called feature?). Is written dead, asked the engineer said this does not change, this is not very pit, if not have a demo, how do I know how to write,,,
As a weak chicken, here I also have questions to ask you:
1. The role of these features, usually write their own code seems to have only used "DataContract"
[System.Runtime.InteropServices.Guid ("1b0535c9-57ad-45c1-9d79-ad5c34360513")] [System.Runtime.InteropServices.InterfaceType ( System.Runtime.InteropServices.ComInterfaceType.InterfaceIsIInspectable)]
Code in 2.MainWindow
var interop = (Iradialcontrollerinterop) System.Runtime.InteropServices.WindowsRuntime.WindowsRuntimeMarshal . Getactivationfactory (typeof (Radialcontroller));
I always feel that reading is so bad, can not understand, perhaps I have never seen, to this method is not familiar?
Microsoft engineers gave me this Demo I found that there are two bugs (he himself also said not finished, is dirty Demo), one is setradialcontrollerconfiguration This method exception, can not be used, resulting in unable to initialize Dial menu, Every time you start the app, it goes to the menu.
Add one, the other is the focus issue, when the long press dial selected other menus, such as volume, and then return to our demo, found at this time dial still control is the volume
Because I am too weak, not much to say, at the end attached to the Dr.neil of the demo of their own research, but also hope that you comment on the answer to my doubts
Link: Http://pan.baidu.com/s/1boJrIbH Password: h722
uwpdesktop! WPF can also develop surface Dial