110 lines
3.7 KiB
C#
110 lines
3.7 KiB
C#
/*
|
|
* Copyright (c) 2022 LG Electronics Inc.
|
|
* SPDX-License-Identifier: LicenseRef-LGE-Proprietary
|
|
*/
|
|
using AuroraUIComponent.UserControls.KeyValueBase;
|
|
using System;
|
|
using System.Globalization;
|
|
using System.Windows;
|
|
using System.Windows.Data;
|
|
|
|
namespace AuroraUIComponent.UserControls
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for UCKeyValueCheckBox.xaml
|
|
/// </summary>
|
|
public partial class UCKeyValueCheckBox : UCKeyValueBase
|
|
{
|
|
public static readonly DependencyProperty ValueBoolProperty
|
|
= DependencyProperty.Register(
|
|
nameof(ValueBool),
|
|
typeof(bool),
|
|
typeof(UCKeyValueCheckBox),
|
|
new FrameworkPropertyMetadata(
|
|
false,
|
|
FrameworkPropertyMetadataOptions.BindsTwoWayByDefault
|
|
));
|
|
|
|
public bool ValueBool {
|
|
get { return (bool)GetValue(ValueBoolProperty); }
|
|
set { SetValue(ValueBoolProperty, value); }
|
|
}
|
|
|
|
public static readonly DependencyProperty TrueValueStrProperty
|
|
= DependencyProperty.Register(
|
|
nameof(TrueValueStr),
|
|
typeof(string),
|
|
typeof(UCKeyValueCheckBox),
|
|
new FrameworkPropertyMetadata(
|
|
"",
|
|
FrameworkPropertyMetadataOptions.BindsTwoWayByDefault
|
|
));
|
|
|
|
public string TrueValueStr {
|
|
get { return (string)GetValue(TrueValueStrProperty); }
|
|
set { SetValue(TrueValueStrProperty, value); }
|
|
}
|
|
|
|
public static readonly DependencyProperty FalseValueStrProperty
|
|
= DependencyProperty.Register(
|
|
nameof(FalseValueStr),
|
|
typeof(string),
|
|
typeof(UCKeyValueCheckBox),
|
|
new FrameworkPropertyMetadata(
|
|
"",
|
|
FrameworkPropertyMetadataOptions.BindsTwoWayByDefault
|
|
));
|
|
|
|
public string FalseValueStr {
|
|
get { return (string)GetValue(FalseValueStrProperty); }
|
|
set { SetValue(FalseValueStrProperty, value); }
|
|
}
|
|
|
|
public UCKeyValueCheckBox()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
protected override void KeyTextChanged(string newValue)
|
|
{
|
|
if (string.IsNullOrEmpty(newValue)) {
|
|
// KeyText 가 없으므로, 해당 grid 의 width 를 0 으로 만든다
|
|
GridParent.ColumnDefinitions[0].Width = new GridLength(0);
|
|
}
|
|
}
|
|
}
|
|
|
|
public class CheckBoxContentConverter : IValueConverter, IMultiValueConverter
|
|
{
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
if (value is bool boolValue && parameter is UCKeyValueCheckBox checkbox) {
|
|
return boolValue ? checkbox.TrueValueStr : checkbox.FalseValueStr;
|
|
}
|
|
|
|
return "";
|
|
}
|
|
|
|
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
if (values != null && values.Length >= 3) {
|
|
if (values[0] is bool boolValue) {
|
|
return boolValue ? values[1] : values[2];
|
|
}
|
|
}
|
|
|
|
return "";
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
}
|