より良いエンジニアを目指して

1日1つ。良くなる!上手くなる!

InkCanvasのGesture認識機能や使えるGesture

エッセンシャルWPFを読んでいたのですが、WPFのInkCanvasにはGesture機能があります。

f:id:rimever:20200701220735p:plain
Check

チェックマークを入力するとチェックのジェスチャーと認識してくれるのです。

AI? 機械学習? 深層学習? とか思い浮かびますが、この本は2007年に発刊されています。

その時点でこんな機能が実現できていたのです。

どんなジェスチャーが認識できるのかというと、以下の列挙型を見ればわかります。

docs.microsoft.com

円や三角形、矢印、星など。

ただ、これを実際の製品に組み込めるかというと微妙です。

チェックマークで書いたつもりでも、Chevron Down(∨という形)として認識されてしまったり、円を書いているつもりでも、No Gestureと認識されないこともあります。

認識できるジェスチャーも特定のものにのみ絞れますが、どうですかねえ。

とはいえ、夢のある機能ですね。

コード

MainWindows.xaml

<Window x:Class="Chapter3_34.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:Chapter3_34"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
<Grid.RowDefinitions>
    <RowDefinition Height="*"/>
    <RowDefinition Height="200"/>
</Grid.RowDefinitions>
        <InkCanvas Grid.Row="0" Name="InkCanvas" Gesture="InkCanvas_OnGesture" EditingMode="InkAndGesture"/>
        <ListBox Name="ListBox1" Grid.Row="1"/>
         </Grid>
</Window>

MainWindow.xaml.cs

#region

using System.Windows;
using System.Windows.Controls;
using System.Windows.Ink;

#endregion

namespace Chapter3_34
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            InkCanvas.SetEnabledGestures(new[] {ApplicationGesture.AllGestures});
        }

        private void InkCanvas_OnGesture(object sender, InkCanvasGestureEventArgs e)
        {
            ListBox1.Items.Add(e.GetGestureRecognitionResults()[0].ApplicationGesture);
        }
    }
}