Is there an event one can listen to that checks for the current state of edit? How can one listen to when the combobox is not in edit mode.
ComboBox(or TextBox) is in edit mode
Ignore the colors, the point is that the ComboBox is in a mode where the user can edit/write text or not. Focus does not work as it can still be in this mode when the combobox is not in focus.
The ComboBox
control has a TextBox
named "EditableText".
private void ComboBox_Loaded(object sender, RoutedEventArgs e)
{
if (sender is not ComboBox comboBox ||
comboBox.FindDescendant<TextBox>(x => x.Name == "EditableText") is not TextBox editableText)
{
return;
}
editableText.GotFocus += EditableText_GotFocus;
editableText.LostFocus += EditableText_LostFocus;
}
private void EditableText_GotFocus(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
{
System.Diagnostics.Debug.WriteLine("EditableText_GotFocus");
}
private void EditableText_LostFocus(object sender, RoutedEventArgs e)
{
System.Diagnostics.Debug.WriteLine("EditableText_LostFocus");
}
The FindDescendant extension comes from the CommunityToolkit.WinUI.Extensions NuGet package.