UwpDesktop! WPF can also develop Surface Dial and uwp1_topwpf.

Source: Internet
Author: User

UwpDesktop! WPF can also develop Surface Dial and uwp1_topwpf.

Some time ago, giant launched a new input device Surface Dial, which is cool to use with Surface Studio.

I am fortunate enough to have participated in Microsoft training because of my company's business. The biggest achievement is that I found that WPF can also develop Dial, while WPF can use UWP APIs!

The key is to add this Nuget in our WPF program. In the previous article, the self-tuning UWP of WPF also uses this nuget.

Because our existing solution is based on wpf, I went straight to the topic and asked the foreigner if this was not magnetic WPF. The answer is yes. So how can we use it? Is there a demo? Yes, you can copy it to me, so we have the demo below.

I should paste the Code directly,

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; ;        }

There is also a key class 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);    }

This class provides the CreateForWindow Method for us to create the RadialController object. I personally think this interface is very mysterious. The Guid feature above (is this a feature ?) I am writing to death. I asked the engineer to say that this does not need to be changed. This is not a pitfall. If there is not a demo, how do I know how to write it ,,,

As a weak chicken, I have some questions here:

1. The functions of these features seem to have been used only for writing code by myself [datacontract]

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

2. MainWindow code

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

I always think that reading is so bad that I can't understand it. Maybe I have never seen it before and I am not familiar with this method?

 

I found two bugs in this Demo that Microsoft engineers gave me (he also said he hasn't finished it yet, Dirty Demo). One is that the SetRadialControllerConfiguration method is abnormal and cannot be used, as a result, the Dial menu cannot be initialized.

Add one item; the other is the focus issue. When we press dial for a long time and select another menu, such as the volume, we return to our demo and find that dial still controls the volume.

As I am too weak, I will not talk much about it. I have attached the demo of Dr. Neil to my end and I hope you can leave a comment to answer my questions.

Link: http://pan.baidu.com/s/1boJrIbH password: 12722



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.