最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

winui 3 - Event when ComboBox goes from edit mode to not - Stack Overflow

programmeradmin2浏览0评论

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

ComboBox is not 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.

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

ComboBox is not 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.

Share Improve this question edited Feb 7 at 11:47 Andrew KeepCoding 13.3k2 gold badges19 silver badges35 bronze badges asked Feb 7 at 8:05 miniHesselminiHessel 8464 gold badges16 silver badges41 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

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.

发布评论

评论列表(0)

  1. 暂无评论