protected override void OnMouseMove(MouseEventArgs e) { if (_imageButtons == null) { return; } foreach (var oneImageButton in _imageButtons) { var images = ButtonImages.GetButtonImages(oneImageButton); if (images == null) { return; } if (oneImageButton.IsMouseOver) { var image = images[1]; oneImageButton.Content = image; } else { var image = images[0]; oneImageButton.Content = image; } } base.OnMouseMove(e); }
public static void OnImageButtonMouseOver(DependencyObject d, DependencyPropertyChangedEventArgs e) { var imageButton = d as ImageButton; if (imageButton == null) { return; } var images = ButtonImages.GetButtonImages(imageButton); if (images == null) { return; } if ((bool)e.NewValue) { var image = images[1]; imageButton.Content = image; } else { var image = images[0]; imageButton.Content = image; } }
private static void Button_MouseEnter(object sender, MouseEventArgs e) { var imageButton = sender as ImageButton; if (imageButton != null && ButtonImages.GetButtonImages(imageButton) == null) { ((Button)sender).Margin = new Thickness(-5); } }
public static Button CreateButton(Image image, string content, string moveEnterImagePath) { Button button; if (image == null) { button = new Button { Content = content }; } else { button = new ImageButton { Content = image }; ButtonImages.SetButtonImages(button, null); if (!string.IsNullOrWhiteSpace(moveEnterImagePath)) { var moveEnterImage = new Image { Source = new BitmapImage(new Uri(moveEnterImagePath)) }; var images = new Image[] { image, moveEnterImage }; ButtonImages.SetButtonImages(button, images); } else { ButtonImages.SetButtonImages(button, null); } } button.HorizontalAlignment = HorizontalAlignment.Center; button.ToolTip = content; button.MouseEnter += Button_MouseEnter; button.MouseLeave += Button_MouseLeave; return(button); }