Files
EngineeringSync/EngineeringSync.Setup/Views/Pages/OptionCard.xaml.cs

48 lines
2.3 KiB
C#
Raw Normal View History

using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace EngineeringSync.Setup.Views.Pages;
public partial class OptionCard : UserControl
{
public static readonly DependencyProperty IconProperty =
DependencyProperty.Register(nameof(Icon), typeof(string), typeof(OptionCard),
new PropertyMetadata(string.Empty, (d, e) => ((OptionCard)d).IconText.Text = (string)e.NewValue));
public static readonly DependencyProperty TitleProperty =
DependencyProperty.Register(nameof(Title), typeof(string), typeof(OptionCard),
new PropertyMetadata(string.Empty, (d, e) => ((OptionCard)d).TitleText.Text = (string)e.NewValue));
public static readonly DependencyProperty DescriptionProperty =
DependencyProperty.Register(nameof(Description), typeof(string), typeof(OptionCard),
new PropertyMetadata(string.Empty, (d, e) => ((OptionCard)d).DescText.Text = (string)e.NewValue));
public static readonly DependencyProperty IsCheckedProperty =
DependencyProperty.Register(nameof(IsChecked), typeof(bool), typeof(OptionCard),
new FrameworkPropertyMetadata(true,
FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
(d, e) => ((OptionCard)d).UpdateVisual((bool)e.NewValue)));
public string Icon { get => (string)GetValue(IconProperty); set => SetValue(IconProperty, value); }
public string Title { get => (string)GetValue(TitleProperty); set => SetValue(TitleProperty, value); }
public string Description { get => (string)GetValue(DescriptionProperty); set => SetValue(DescriptionProperty, value); }
public bool IsChecked { get => (bool)GetValue(IsCheckedProperty); set => SetValue(IsCheckedProperty, value); }
public OptionCard() => InitializeComponent();
private void Card_Click(object sender, RoutedEventArgs e) => IsChecked = !IsChecked;
private void UpdateVisual(bool isChecked)
{
if (ToggleBox is null) return;
ToggleBox.IsChecked = isChecked;
CardBorder.BorderBrush = isChecked
? new SolidColorBrush(Color.FromRgb(0, 120, 212))
: new SolidColorBrush(Color.FromRgb(224, 224, 224));
CardBorder.Background = isChecked
? new SolidColorBrush(Color.FromArgb(15, 0, 120, 212))
: new SolidColorBrush(Colors.White);
}
}