Search code examples
wpftouchstylus-pen

Detect stylus eraser button on WPF


Is there any way to detect that the stylus eraser button is pressed on a WPF element?


Solution

  • The answer seems to be to detect if the pen is Inverted. http://msdn.microsoft.com/EN-US/library/ms607230(VS.110).aspx

    (tested on Lenovo x61 tablet)

    In MainWindow.Xaml

    <TextBlock Name="textBox"
            Text="Hello World!" HorizontalAlignment="Center" VerticalAlignment="Center"
            StylusDown="TextBlock_StylusDown_1"/>
    

    In MainWindow.Xaml.cs

     private void TextBlock_StylusDown_1(object sender, StylusDownEventArgs e)
        {
            if (e.Inverted)
                textBox.Text = "I've been erased";
            else
                textBox.Text = "Normal stylus";
        }