/* * Copyright (c) 2022 LG Electronics Inc. * SPDX-License-Identifier: LicenseRef-LGE-Proprietary */ using AuroraUIComponent.UserControls.KeyValueBase; using System; using System.Globalization; using System.Linq; using System.Windows; using System.Windows.Data; using System.Windows.Media; namespace AuroraUIComponent.UserControls { /// /// Interaction logic for UCKeyValue.xaml /// public partial class UCKeyValueMonitor : UCKeyValueNumber { public static readonly DependencyProperty CornorRadiusProperty = DependencyProperty.Register( nameof(CornorRadius), typeof(CornerRadius), typeof(UCKeyValueMonitor), new PropertyMetadata(new CornerRadius(6))); public CornerRadius CornorRadius { get { return (CornerRadius)GetValue(CornorRadiusProperty); } set { SetValue(CornorRadiusProperty, value); } } public static readonly DependencyProperty ControlBackgroundProperty = DependencyProperty.Register( nameof(ControlBackground), typeof(SolidColorBrush), typeof(UCKeyValueMonitor), new FrameworkPropertyMetadata( (SolidColorBrush)Application.Current.Resources["MahApps.Brushes.BackgroundSelected"], FrameworkPropertyMetadataOptions.BindsTwoWayByDefault)); public SolidColorBrush ControlBackground { get { return (SolidColorBrush)GetValue(ControlBackgroundProperty); } set { SetValue(ControlBackgroundProperty, value); } } public static readonly DependencyProperty ControlPaddingProperty = DependencyProperty.Register( nameof(ControlPadding), typeof(Thickness), typeof(UCKeyValueMonitor), new PropertyMetadata(new Thickness(20, 0, 20, 0))); public Thickness ControlPadding { get { return (Thickness)GetValue(ControlPaddingProperty); } set { SetValue(ControlPaddingProperty, value); } } public UCKeyValueMonitor() : base() { InitializeComponent(); TextValue.LostFocus += TextBoxOnLostFocus; } private void TextBoxOnLostFocus(object sender, RoutedEventArgs e) { Value = ParseString2Decimal(TextValue.Text); } protected override void ChangeThousandSeparator(decimal value) { //change formatting based on this flag if (ThousandSeparator) { if (TextValue.Text != null) { TextValue.Text = value.ToString("N", Culture); } } else { if (TextValue.Text != null) { TextValue.Text = value.ToString($"F", Culture); } } } protected override void KeyTextChanged(string newValue) { if (string.IsNullOrEmpty(newValue)) { // KeyText 가 없으므로, 해당 grid 의 width 를 0 으로 만든다 if (GridParent.ColumnDefinitions.Count > 0) { GridParent.ColumnDefinitions[0].Width = new GridLength(0); } if (GridParent.RowDefinitions.Count > 0) { GridParent.RowDefinitions[0].Height = new GridLength(0); } } } } }