pastaCSharp

Autor:

| Größe: 9.08 KB

|

правый блок <Border x:Name="PreviewBorder" Width="400" Height="200" CornerRadius="10" Padding="20">  <Border.Background> <Binding Path="BackgroundColor" Converter="{StaticResource GradientBackgroundConverter}"/> </Border.Background>  MainWindow.xaml.cs using SettingsMasterApp.ViewModels; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; 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.Animation; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using System.Windows.Threading;  namespace SettingsMasterApp { /// <summary> /// Логика взаимодействия для MainWindow.xaml /// </summary> public partial class MainWindow : Window { private DispatcherTimer _animationTimer; private Color _startColor; private Color _targetColor; private DateTime _animationStartTime; private const double AnimationDuration = 0.5;  public MainWindow() { InitializeComponent(); DataContext = new SettingsViewModel();  _animationTimer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(16) }; _animationTimer.Tick += AnimationTimer_Tick;  if (DataContext is SettingsViewModel vm) { vm.PropertyChanged += Vm_PropertyChanged; } }  private void Vm_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { if (e.PropertyName == "Theme") { StartThemeAnimation(); } }  private void StartThemeAnimation() { var vm = DataContext as SettingsViewModel; if (vm == null) return;  _startColor = vm.BackgroundColor; _targetColor = vm.Theme == "Dark" ? Color.FromRgb(40, 40, 50) : Colors.WhiteSmoke;  _animationStartTime = DateTime.Now; _animationTimer.Start(); }  private void AnimationTimer_Tick(object sender, EventArgs e) { var vm = DataContext as SettingsViewModel; if (vm == null) { _animationTimer.Stop(); return; }  var elapsed = (DateTime.Now - _animationStartTime).TotalSeconds; var progress = Math.Min(1.0, elapsed / AnimationDuration);  double eased = progress < 0.5 ? 2 * progress * progress : 1 - Math.Pow(-2 * progress + 2, 2) / 2;  byte r = (byte)(_startColor.R + (_targetColor.R - _startColor.R) * eased); byte g = (byte)(_startColor.G + (_targetColor.G - _startColor.G) * eased); byte b = (byte)(_startColor.B + (_targetColor.B - _startColor.B) * eased);  vm.BackgroundColor = Color.FromRgb(r, g, b);  if (progress >= 1.0) { _animationTimer.Stop(); vm.BackgroundColor = _targetColor; } } } }  SettingsViewModel.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.ComponentModel; using System.Runtime.CompilerServices; using System.Windows.Media;  namespace SettingsMasterApp.ViewModels { public class SettingsViewModel : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged;  private double _opacity = 0.8; public double Opacity { get => _opacity; set => SetField(ref _opacity, value); }  private bool _isEnabled = true; public bool IsEnabled { get => _isEnabled; set => SetField(ref _isEnabled, value); }  private string _theme = "Light"; public string Theme { get => _theme; set => SetField(ref _theme, value); }  private Color _backgroundColor = Colors.White; public Color BackgroundColor { get => _backgroundColor; set => SetField(ref _backgroundColor, value); }  private Color _textColor = Colors.Black; public Color TextColor { get => _textColor; set => SetField(ref _textColor, value); }  private double _fontSize = 14; public double FontSize { get => _fontSize; set => SetField(ref _fontSize, value); …

Kommentare

Noch keine Kommentare

Comment attachments are limited to 30MB total. For larger files, create a paste and share the link.

3/31/2026

Neuen Paste mit denselben Einstellungen erstellen

Nicht alle benutzergenerierten Inhalte werden von AnonPaste überprüft. Wenn du glaubst, dass dieser Paste unsere Community-Richtlinien or Nutzungsbedingungen, verletzt, bitte melde ihn hier.

Initializing...

Preparing the app. This may take a moment before app is ready.

AnonPaste ist ein Hosting-Service für benutzergenerierte Inhalte. Die Plattform und ihre Betreiber sind nicht für Inhalte verantwortlich, die von Benutzern veröffentlicht wurden.