SetterViewModel.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using Avalonia.Input.Platform;
  2. namespace Avalonia.Diagnostics.ViewModels
  3. {
  4. internal class SetterViewModel : ViewModelBase
  5. {
  6. private bool _isActive;
  7. private bool _isVisible;
  8. public AvaloniaProperty Property { get; }
  9. public string Name { get; }
  10. public object Value { get; }
  11. public bool IsActive
  12. {
  13. get => _isActive;
  14. set => RaiseAndSetIfChanged(ref _isActive, value);
  15. }
  16. public bool IsVisible
  17. {
  18. get => _isVisible;
  19. set => RaiseAndSetIfChanged(ref _isVisible, value);
  20. }
  21. public SetterViewModel(AvaloniaProperty property, object value)
  22. {
  23. Property = property;
  24. Name = property.Name;
  25. Value = value;
  26. IsActive = true;
  27. IsVisible = true;
  28. }
  29. public void CopyValue()
  30. {
  31. if (Value is null)
  32. {
  33. return;
  34. }
  35. CopyToClipboard(Value.ToString());
  36. }
  37. public void CopyPropertyName()
  38. {
  39. CopyToClipboard(Property.Name);
  40. }
  41. protected static void CopyToClipboard(string value)
  42. {
  43. var clipboard = AvaloniaLocator.Current.GetService<IClipboard>();
  44. clipboard?.SetTextAsync(value);
  45. }
  46. }
  47. }