Skip to content

Conversation

@Keboo
Copy link
Member

@Keboo Keboo commented Feb 8, 2024

This revert the fix that was done for #3249.
Need to revisit fix that was done and find an alternative.

@AndrewKeepCoding if you are able, do you mind taking a look and seeing if there is a way to limit how often we call SetFocus as it appear to close the popup in the ComboBox.

This revert the fix that was done for #3249.
Need to revisit fix that was done and find an alternative.
@Keboo Keboo added this to the 5.0.0 milestone Feb 8, 2024
@AndrewKeepCoding
Copy link
Contributor

@Keboo I created a test app with minimal code (C# only) that reproduces the issue.

These 3 reproduce the issue:

private async void Button_Click(object sender, RoutedEventArgs e)
{
    ComboBox comboBox = new ComboBox();
    comboBox.Items.Add("A");
    comboBox.Items.Add("B");
    comboBox.Items.Add("C");
    await MaterialDesignThemes.Wpf.DialogHost.Show(comboBox);
}

or

private void DialogHost_Loaded(object sender, RoutedEventArgs e)
{
    if (sender is not MaterialDesignThemes.Wpf.DialogHost dialogHost)
    {
        return;
    }

    ComboBox comboBox = new ComboBox();
    comboBox.Items.Add("A");
    comboBox.Items.Add("B");
    comboBox.Items.Add("C");
    dialogHost.ShowDialog(comboBox);
    // The code below also reproduces the issue.
    // dialogHost.DialogContent = comboBox;
    // dialogHost.IsOpen = true;
}

I also confirmed that by commenting out the SetFocust() on DialogHost.cs the ComboBox shows its items.

@AndrewKeepCoding
Copy link
Contributor

Assuming that we only need to set the focus ONCE when the dialog is opened, why not just remove the event handler?

private void OnPreviewGotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
{
    if (_popup != null &&
        PresentationSource.FromVisual(_popup.Child) is HwndSource hwndSource)
     {
        SetFocus(hwndSource.Handle);
        PreviewGotKeyboardFocus -= OnPreviewGotKeyboardFocus;
    }
}

This way nobody makes the ComboBox hide its items.

@Keboo
Copy link
Member Author

Keboo commented Feb 13, 2024

Assuming that we only need to set the focus ONCE when the dialog is opened, why not just remove the event handler?

private void OnPreviewGotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
{
    if (_popup != null &&
        PresentationSource.FromVisual(_popup.Child) is HwndSource hwndSource)
     {
        SetFocus(hwndSource.Handle);
        PreviewGotKeyboardFocus -= OnPreviewGotKeyboardFocus;
    }
}

This way nobody makes the ComboBox hide its items.

Perfect, yea given that it is hard for me to reproduce the original issue that was fixed by this, I wanted to confirm I wasn't going to re-break it.

@Keboo Keboo enabled auto-merge (squash) February 13, 2024 06:54
@Keboo Keboo merged commit c338f12 into master Feb 13, 2024
@Keboo Keboo deleted the issue3450 branch February 13, 2024 07:07
@Keboo Keboo mentioned this pull request Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants