Desktop applications migrate to MS Store (12) - WPF and the UWP InkToolbar use InkCanvas

We "desktop program to migrate MS Store (4) - Desktop program calls the Win10 API" referred calls to the Win10 API, but there are still problems can not be used UWP controls in WPF, XAML controls though it is, but it is two types of the same name in the namespace, you can not mix.
People will always be defeated reality, as strong as they have to bow to a soft life, UWP has been no improvement, the boss of a soft and wholeheartedly engage in Azure. Revive the Windows platform, seems to want to go back and start from the 1903 version, support for .NET Framwork of WPF and WinForm project, directly controls part of the UWP. Bear the brunt of that is a bit Saobao InkToolbar and InkCanvas.

Next we will try how WPF project, using the UWP InkToolbar and InkCanvas.
First, create an empty WPF project, after completion, the search interface Nuget fill Microsoft.Toolkit.Wpf.UI.Controls, select the first installation.

After installation is complete, the MainWindow.xaml open, add a reference to the namespace xmlns: Controls = "clr-namespace: Microsoft.Toolkit.Wpf.UI.Controls; assembly = Microsoft.Toolkit.Wpf.UI.Controls". Then you can add UWP version of InkToolbar and InkCanvas controls in the <Grid> node.

<Window x:Class="WPFInkSample.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WPFInkSample"
        xmlns:Controls="clr-namespace:Microsoft.Toolkit.Wpf.UI.Controls;assembly=Microsoft.Toolkit.Wpf.UI.Controls"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid >
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Controls:InkToolbar TargetInkCanvas="{x:Reference myInkCanvas}" Grid.Row="0" />
        <Controls:InkCanvas x:Name="myInkCanvas" Grid.Row="1" />
    </Grid>
</Window>

We also need to set InputDeviceTypes in MainWindow.xaml.cs in.

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            this.myInkCanvas.InkPresenter.InputDeviceTypes = CoreInputDeviceTypes.Mouse | CoreInputDeviceTypes.Pen;
        }
    }

Then press F5 to run, a soft Sao operation came ...... because only after the 1903 edition of this show is supported operations (10.0.18226 is an earlier preview version), so it is necessary to do additional processing before they can.

我们这里有两种选择,一是通过《迁移桌面程序到MS Store(1)——通过Visual Studio创建Packaging工程》来打包这个WPF程序,然后在Packaging工程的属性里,将Target version和Minimum version同时设置为Windows 10, version 1903 (10.0.18362) 。这是MSDN上推荐的标准做法,这样做的好处在于,打包好的程序可以直接上传MS Store。
如果我们想保持exe的可执行文件形式,还有另一种做法,在Project文件上右键点击Add->New Item,添加一个manifest文件。
在这个文件中,找到<!--Windows 10-->,然后做如下编辑:

  <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
    <application>
      <!-- A list of the Windows versions that this application has been tested on
           and is designed to work with. Uncomment the appropriate elements
           and Windows will automatically select the most compatible environment. -->
  
      <!-- Windows Vista -->
      <!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />-->
  
      <!-- Windows 7 -->
      <!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />-->
  
      <!-- Windows 8 -->
      <!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />-->
  
      <!-- Windows 8.1 -->
      <!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />-->
  
      <!-- Windows 10 -->
      <maxversiontested Id="10.0.18362.0"/>
      <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
  
    </application>
  </compatibility>

Once saved, and then run through F5, which found that everything is normal, the error does not occur when running before.
This article, we describe how to use the UWP InkToolbar and InkCavas in WPF project. Because this feature is only supported version after 1903, so next we will explain how to easily determine the Win10 API version, to determine whether the corresponding version of the code is executed at runtime.
GitHub:
https://github.com/manupstairs/WPFInkSample.git

Guess you like

Origin www.cnblogs.com/manupstairs/p/11936917.html
UWP