using System.Windows; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; using SparkClient.ViewModel.BaseWindow; namespace SparkClient.Views.BaseWindow; public partial class HomeWindow { public HomeWindow() { InitializeComponent(); } private void UIElement_OnMouseLeave(object sender, MouseEventArgs e) { if (sender is Border border) { var gradientBrush = new RadialGradientBrush(); // 设置渐变起始点和中心点 gradientBrush.GradientOrigin = new Point(0.5, 0.5); // 中心点 gradientBrush.Center = new Point(0.5, 0.5); // 设置渐变半径 gradientBrush.RadiusX = 0.5; gradientBrush.RadiusY = 0.5; // 添加渐变颜色 gradientBrush.GradientStops.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#FF4C4D4F"), 0.0)); // 内部颜色 gradientBrush.GradientStops.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#FF944703"), 2.0)); // 外部颜色 // 应用到 Border 的背景 border.Background = gradientBrush; //border.Background = new SolidColorBrush(Colors.Transparent); } } private void UIElement_OnMouseEnter(object sender, MouseEventArgs e) { if (sender is Border border) { var gradientBrush = new RadialGradientBrush(); // 设置渐变起始点和中心点 gradientBrush.GradientOrigin = new Point(0.5, 0.5); // 中心点 gradientBrush.Center = new Point(0.5, 0.5); // 设置渐变半径 gradientBrush.RadiusX = 0.5; gradientBrush.RadiusY = 0.5; // 添加渐变颜色 gradientBrush.GradientStops.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#FF4C4D4F"), 0.0)); // 内部颜色 gradientBrush.GradientStops.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#FF944703"), 1.0)); // 外部颜色 // 应用到 Border 的背景 border.Background = gradientBrush; // border.Background = new SolidColorBrush(Color.FromArgb(50, 255, 255, 255)); } } }