Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RibbonTabItem.IsSelected is briefly set to true for a tab that's not selected anymore, when a modal dialog is closed. #856

Closed
HorpeHUN opened this issue Oct 13, 2020 · 3 comments
Assignees
Labels
Milestone

Comments

@HorpeHUN
Copy link

I have a very simple test app that has two ribbon tabs. The IsSelected property of these tabs are data bound to two properties. If the data bound property becomes true, a message box is displayed.

But if you close the message box, then the other tabs IsSelected property turns to true somehow, and the another message box gets displayed

MainWindow.xaml

        <Fluent:Ribbon>
            <Fluent:RibbonTabItem Header="First" IsSelected="{Binding ElementName=MyWindow, Path=IsFirstSelected}"/>
            <Fluent:RibbonTabItem Header="Second" IsSelected="{Binding ElementName=MyWindow, Path=IsSecondSelected}"/>
        </Fluent:Ribbon>

MainWindow.cs

bool isFirstSelected;
bool isSecondSelected;

public bool IsFirstSelected
{
    get { return isFirstSelected; }
    set
    {
        if (isFirstSelected != value)
        {
            isFirstSelected = value;

            if (value)
                MessageBox.Show("IsFirstSelected is now set to true.");
        }
    }
}


public bool IsSecondSelected
{
    get { return isSecondSelected; }
    set
    {
        if (isSecondSelected != value)
        {
            isSecondSelected = value;
            if (value)
                MessageBox.Show("IsSecondSelected is now set to true.");
        }
    }
}

bug

Source code:
RibbonTest.zip


Environment

  • Fluent.Ribbon v8.0.0
  • Windows 10
  • .NET Framework 4.7.2
@batzen batzen self-assigned this Oct 13, 2020
@batzen batzen added this to the Next milestone Oct 13, 2020
@batzen batzen removed the Bug 🐞 label Oct 13, 2020
@batzen batzen removed this from the Next milestone Oct 13, 2020
@batzen
Copy link
Member

batzen commented Oct 13, 2020

Just had a look and first thought that it's a ribbon issue, but i think it's not.
Showing a messagebox, and thus causing a modal message loop, when setting a dependency property confuses the WPF input system somehow.
If you show the messagebox async like
this.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => MessageBox.Show("IsFirstSelected is now set to true.")));
the issue is gone. If you set a breakpoint on the lines showing the messagebox you can see from the call stack that we get a WM_SETFOCUS window message when closing the messagebox which causes wpf the send a PreviewGotKeyboardFocus event to the other tab item.

@HorpeHUN
Copy link
Author

We have switched from the Microsoft Ribbon (System.Windows.Controls.Ribbon) to this library, and we didn't have this problem with that. That doesn't set IsSelected to true in PreviewGotKeyboardFocus .

In our application, the main content changes when you change from one Tab to another. In some cases that takes a bit of time and a progress bar is displayed. And when the progress bar is closed, then the application starts switching back to the previous tab, and that causes problems.

We'll need to create a workaround, like ignoring the change of the IsSelected property when a change is already underway.
I still think this is a bug. Showing a dialog in one tab's IsSelected property setter sets another tab's IsSelected property to true as a side effect.

RibbonTest.exe!RibbonTest.MainWindow.IsFirstSelected.set(bool value = true) Line 17 C# Fluent.dll!Fluent.RibbonTabItem.OnPreviewGotKeyboardFocus(System.Windows.Input.KeyboardFocusChangedEventArgs e = {System.Windows.Input.KeyboardFocusChangedEventArgs}) Line 582 C# PresentationFramework.dll!System.Windows.MessageBox.Show(string messageBoxText) Line 135 C# RibbonTest.exe!RibbonTest.MainWindow.IsSecondSelected.set(bool value = true) Line 35 C#

@batzen
Copy link
Member

batzen commented Oct 14, 2020

I agree that it behaves a bit strange and I am not sure why that code, inside PreviewGotKeyboardFocus, exists.
Give me a few days to think about it.

@batzen batzen closed this as completed in 1d08483 Oct 22, 2020
@batzen batzen added this to the Next milestone Oct 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants