Everytime i use touchdown event in a button/rectangle or whatever it uses a lot of cpu the more objects i touch. Is there another way to make an event happen only once when i touch a object because touchdown is doing something that is constantly using cpu while i hold down. In my program i need to make something happen once when i touch an object and do another thing once when i stop touching it, to be more exact its to make a boolean true and false. Anyway here is the code
using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Interop; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace sendString { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); Stylus.SetIsPressAndHoldEnabled(this, false); } private const int GWL_EXSTYLE = -20; private const int WS_EX_NOACTIVATE = 0x08000000; [DllImport("user32.dll")] public static extern IntPtr SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong); [DllImport("user32.dll")] public static extern int GetWindowLong(IntPtr hWnd, int nIndex); protected override void OnActivated(EventArgs e) { base.OnActivated(e); //Set the window style to noactivate. WindowInteropHelper helper = new WindowInteropHelper(this); SetWindowLong(helper.Handle, GWL_EXSTYLE, GetWindowLong(helper.Handle, GWL_EXSTYLE) | WS_EX_NOACTIVATE); } private void Button_TouchDown(object sender, TouchEventArgs e) { Console.WriteLine("1111"); } private void Button_TouchDown_1(object sender, TouchEventArgs e) { Console.WriteLine("22222"); } } }
<Window x:Class="sendString.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"><Grid><Button Content="Button" HorizontalAlignment="Left" VerticalAlignment="Top" Width="170" Height="79" Margin="190,0,0,0" TouchDown="Button_TouchDown"/><Button Content="Button" HorizontalAlignment="Left" VerticalAlignment="Top" Width="185" Height="79" Margin="190,155,0,0" TouchDown="Button_TouchDown_1"/></Grid></Window>