101 lines
3.3 KiB
C#
101 lines
3.3 KiB
C#
/*
|
|
* Copyright (c) 2022 LG Electronics Inc.
|
|
* SPDX-License-Identifier: LicenseRef-LGE-Proprietary
|
|
*/
|
|
|
|
using AuroraUIComponent.UserControls.KeyValueBase;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Windows;
|
|
|
|
namespace AuroraUIComponent.UserControls
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for UCKeyComboBox.xaml
|
|
/// </summary>
|
|
public partial class UCKeyComboBoxNumber : UCKeyValueBase
|
|
{
|
|
public static readonly DependencyProperty ValueTextProperty
|
|
= DependencyProperty.Register(
|
|
nameof(ValueText),
|
|
typeof(int),
|
|
typeof(UCKeyComboBoxNumber),
|
|
new FrameworkPropertyMetadata(
|
|
0,
|
|
FrameworkPropertyMetadataOptions.BindsTwoWayByDefault
|
|
));
|
|
|
|
public object ValueText {
|
|
get { return GetValue(ValueTextProperty); }
|
|
set { SetValue(ValueTextProperty, value); }
|
|
}
|
|
|
|
public static readonly DependencyProperty MinValueProperty
|
|
= DependencyProperty.Register(
|
|
nameof(MinValue),
|
|
typeof(int),
|
|
typeof(UCKeyComboBoxNumber),
|
|
new FrameworkPropertyMetadata(
|
|
0,
|
|
FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnMinMaxValueChanged));
|
|
|
|
public int MinValue {
|
|
get { return (int)GetValue(MinValueProperty); }
|
|
set { SetValue(MinValueProperty, value); }
|
|
}
|
|
|
|
public static readonly DependencyProperty MaxValueProperty
|
|
= DependencyProperty.Register(
|
|
nameof(MaxValue),
|
|
typeof(int),
|
|
typeof(UCKeyComboBoxNumber),
|
|
new FrameworkPropertyMetadata(
|
|
2,
|
|
FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnMinMaxValueChanged));
|
|
|
|
public int MaxValue {
|
|
get { return (int)GetValue(MaxValueProperty); }
|
|
set { SetValue(MaxValueProperty, value); }
|
|
}
|
|
|
|
private static void OnMinMaxValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
|
{
|
|
if (d is UCKeyComboBoxNumber sender) {
|
|
sender.ResizeComboBox();
|
|
}
|
|
}
|
|
public UCKeyComboBoxNumber()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
public override void EndInit()
|
|
{
|
|
ResizeComboBox();
|
|
|
|
base.EndInit();
|
|
}
|
|
|
|
private void ResizeComboBox()
|
|
{
|
|
if (KeyText != null) {
|
|
List<int> list = new List<int>();
|
|
for (int i = MinValue; i <= MaxValue; i++) {
|
|
list.Add(i);
|
|
}
|
|
|
|
TextValue.ItemsSource = list;
|
|
TextValue.SelectedItem = ValueText;
|
|
}
|
|
}
|
|
|
|
protected override void KeyTextChanged(string newValue)
|
|
{
|
|
if (string.IsNullOrEmpty(newValue)) {
|
|
// KeyText 가 없으므로, 해당 grid 의 width 를 0 으로 만든다
|
|
GridParent.ColumnDefinitions[0].Width = new GridLength(0);
|
|
}
|
|
}
|
|
}
|
|
}
|