private void UserControl_MouseMove(object sender, MouseEventArgs e) //鼠标移动 { foreach (TimeFormat thisItem in StateData) { if (thisItem.Rect == null) { continue; } if (thisItem.Rect.Margin.Left > 0) { thisItem.Rect.Margin = new Thickness(0); thisItem.Rect.Width = thisItem.Widht; thisItem.Rect.Height = thisItem.Height; } } double x = e.GetPosition(cvMain).X; double y = e.GetPosition(cvMain).Y; if ((x < 0) || (x > cvMain.ActualWidth) || (y < 0) || (y > cvMain.ActualHeight)) { ToolTipService.SetIsEnabled(cvMain, false); return; } TimeFormat item = StateData.FirstOrDefault(c => (c.Left <= x) && (c.Right >= x)); if (item == null) { ToolTipService.SetIsEnabled(cvMain, false); return; } ToolTipService.SetIsEnabled(cvMain, !string.IsNullOrEmpty(StateToolTipFormat)); if (IsMouseOverShow) //鼠标移上后显示 { item.Rect.Margin = new Thickness(2); item.Rect.Width = item.Widht - 4; item.Rect.Height = item.Height - 4; } if (!string.IsNullOrEmpty(StateToolTipFormat)) { string tipString = StateToolTipFormat; tipString = tipString.Replace("(Name)", item.Name ?? ""); tipString = tipString.Replace("(BeginTime)", item.BeginTime.ToString()); tipString = tipString.Replace("(EndTime)", item.EndTime.ToString()); tipString = tipString.Replace("(StateText)", item.StateText ?? ""); tipString = tipString.Replace("\\n", Environment.NewLine); tbToolTip.Text = tipString; } this.RaiseEvent(new RoutedEventArgs(StateItemMouseMoveEvent, item)); }
private void UserControl_MouseDown(object sender, MouseButtonEventArgs e) { double x = e.GetPosition(cvMain).X; double y = e.GetPosition(cvMain).Y; if ((x < 0) || (x > cvMain.ActualWidth) || (y < 0) || (y > cvMain.ActualHeight)) { return; } TimeFormat item = StateData.FirstOrDefault(c => (c.Left <= x) && (c.Right >= x)); if (item == null) { return; } this.RaiseEvent(new RoutedEventArgs(StateItemMouseDownEvent, item)); }