diff --git a/src/Libraries/CoreNodeModelsWpf/NodeViewCustomizations/DefineData.cs b/src/Libraries/CoreNodeModelsWpf/NodeViewCustomizations/DefineData.cs index 5cf75287257..68a15726159 100644 --- a/src/Libraries/CoreNodeModelsWpf/NodeViewCustomizations/DefineData.cs +++ b/src/Libraries/CoreNodeModelsWpf/NodeViewCustomizations/DefineData.cs @@ -139,7 +139,7 @@ public void CustomizeView(DefineData model, NodeView nodeView) VerticalAlignment = VerticalAlignment.Top, VerticalContentAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Left, - MinWidth = model.IsAutoMode ? 220 : 240, // initial value only, will change on enabled/disabled (crops the combobox arrow otherwise) + MinWidth = 200, Height = 30, FontSize = 12, Background = new SolidColorBrush(Color.FromRgb(42, 42, 42)), @@ -154,6 +154,13 @@ public void CustomizeView(DefineData model, NodeView nodeView) }; selectedItemDisplay.SetBinding(TextBox.TextProperty, selectedItemBinding); + var widthBinding = new Binding("IsEnabled") + { + Source = selectedItemDisplay, + Converter = new BooleanToWidthConverter() + }; + selectedItemDisplay.SetBinding(TextBox.WidthProperty, widthBinding); + // Move the ComboBox to the placeholder var placeholderText = formControl.FindName("TextPlaceholder") as TextBox; @@ -172,8 +179,6 @@ public void CustomizeView(DefineData model, NodeView nodeView) Panel.SetZIndex(selectedItemDisplay, 2); Panel.SetZIndex(dropdown, 1); } - - selectedItemDisplay.IsEnabledChanged += selectedItemDisplay_IsEnabledChanged; } public new void Dispose() @@ -184,11 +189,6 @@ public void CustomizeView(DefineData model, NodeView nodeView) dropdown.DropDownClosed -= dropDown_DropDownClosed; } - if (selectedItemDisplay != null) - { - selectedItemDisplay.IsEnabledChanged -= selectedItemDisplay_IsEnabledChanged; - } - if (listToggleButton != null) { listToggleButton.Click -= listToggle_IsClicked; @@ -217,14 +217,6 @@ private void dropDown_DropDownClosed(object sender, EventArgs e) } } - private void selectedItemDisplay_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e) - { - if (sender is TextBox textBox) - { - textBox.MinWidth = textBox.IsEnabled ? 200 : 220; - } - } - private void listToggle_IsClicked(object sender, RoutedEventArgs e) { if (modeToggleButton != null && modeToggleButton.IsChecked == true) @@ -309,5 +301,19 @@ public object ConvertBack(object value, Type targetType, object parameter, Cultu throw new NotImplementedException(); } } + + public class BooleanToWidthConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + bool isEnabled = (bool)value; + return isEnabled ? 200 : 220; + } + + public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + throw new NotImplementedException(); + } + } } }