Skip to content

Commit

Permalink
refactor resolve potential timeout
Browse files Browse the repository at this point in the history
- removed event subscription, replaced with binding in an attempt to resolve timeout issue
  • Loading branch information
dnenov committed May 22, 2024
1 parent d3888df commit fdba6e9
Showing 1 changed file with 22 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand All @@ -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;
Expand All @@ -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()
Expand All @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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();
}
}
}
}

0 comments on commit fdba6e9

Please sign in to comment.