salve a tutti,
Sto creando un'applicazione che incapsula un controllo wpf (tastiera su schermo) il mio problema è che con il dispatcher riesco a nascondere il controllo dopo 10 secondi per riattivare il controllo volevo utilizzare il movimento del mouse ma nel momento in cui muovo il mouse all'interno del form attivo il controllo si riapre ma in un numero infinito di volte di seguito il codice del controllo xaml.cs
codice:using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; using System.Threading; using System.Windows.Threading; using System.Windows.Interop; using System.Runtime.InteropServices; using System.ComponentModel; using System.Windows.Forms; using System.Windows.Markup; using System.Diagnostics; using System.Reflection; namespace BensOSK { /// <summary> /// Interaction logic for BensOnScreenKeyboardWindow.xaml /// </summary> public partial class BensOnScreenKeyboardWindow : Window { private EventHandler handler; /// <summary> /// Create a new BensOnScreenKeyboardWindow /// </summary> public BensOnScreenKeyboardWindow() { InitializeComponent(); // add keyboard this.keyGrid.Children.Add(new BensOnScreenKeyboard(this)); handler = delegate { DispatcherTimer timer = new DispatcherTimer(); timer.Interval = TimeSpan.FromSeconds(10); timer.Tick += delegate { if (timer != null) { timer.Stop(); timer = null; System.Windows.Interop.ComponentDispatcher.ThreadIdle -= handler; this.Hide(); System.Windows.Interop.ComponentDispatcher.ThreadIdle += handler; } }; timer.Start(); Dispatcher.CurrentDispatcher.Hooks.OperationPosted += delegate { if (timer != null) timer.Stop(); timer = null; }; }; ComponentDispatcher.ThreadIdle += handler; } /// <summary> /// Create a new BensOnScreenKeyboardWindow /// </summary> /// <param name="focusableElement">Specifies element to hold keyboards focus</param> public BensOnScreenKeyboardWindow(IInputElement focusableElement) { InitializeComponent(); // add keyboard this.keyGrid.Children.Add(new BensOnScreenKeyboard(focusableElement)); } /// <summary> /// Setup this window /// </summary> private void setupKeyboardWindow() { // set top this.Top = SystemParameters.PrimaryScreenHeight - this.Height; // set left this.Left = 150; // set width this.Width = SystemParameters.PrimaryScreenWidth; } /// <summary> /// Set the apps skin /// </summary> /// <param name="skinName"></param> private void setSkin(String skinName) { // create uri to skin Uri skinUri = new Uri(String.Format("/Skins/{0}.xaml", skinName), UriKind.Relative); // tell app to load skins App app = System.Windows.Application.Current as App; // load skins app.ApplySkin(skinUri); } private void Window_Initialized(object sender, EventArgs e) { // setup this.setupKeyboardWindow(); } private void normalButton_Click(object sender, RoutedEventArgs e) { // set skin this.setSkin(normalButton.CommandParameter.ToString()); } private void blackButton_Click(object sender, RoutedEventArgs e) { // set skin this.setSkin(blackButton.CommandParameter.ToString()); } private void blueButton_Click(object sender, RoutedEventArgs e) { // set skin this.setSkin(blueButton.CommandParameter.ToString()); } } }

Rispondi quotando