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

The elements in the ribbon use ElementName = xxx to bind the data and cannot find the xxx element #798

Closed
845669495 opened this issue May 14, 2020 · 8 comments
Assignees
Labels
Milestone

Comments

@845669495
Copy link

Conditions that trigger bugs:

  1. Ribbon exists in TabItem under TabControl;
  2. TabControl has multiple TabItems;
  3. The TabItem where the Ribbon is located is not selected when starting the software;

When the above conditions are met, any element in the Ribbon cannot find the element by data binding using the "{Binding ElementName = xxx}" method.

Hope this bug can be fixed, thank you very much!


Environment

  • Fluent.Ribbon __v8.0.0-alpha0077
  • Windows __win10
  • .NET Framework __4.6.1
@845669495
Copy link
Author

845669495 commented May 14, 2020

<TabControl>
    <TabItem Header="tab1" IsSelected="True">
    </TabItem>
    <TabItem Header="tab2">
        <StackPanel>
            <Fluent:Ribbon>
                <Fluent:RibbonTabItem Header="Main">
                    <Fluent:RibbonGroupBox>
                        <Fluent:ToggleButton LargeIcon="1.png" IsChecked="{Binding ElementName=cb1,Path=IsChecked}"></Fluent:ToggleButton>
                    </Fluent:RibbonGroupBox>
                </Fluent:RibbonTabItem>
            </Fluent:Ribbon>
            <CheckBox x:Name="cb1">checkBox1</CheckBox>
        </StackPanel>
    </TabItem>
</TabControl>

The above is the example code. Normally, the selected state of ToggleButton should follow checkBox1, but in fact this data binding has not worked.

@batzen
Copy link
Member

batzen commented May 14, 2020

That's nothing i can do about.
ElementName only works if the element has been loaded.
What you could try is to use TabControlEx from ControlzEx and select every tab in your tabcontrol once when your UI is loaded and set the selection back to the initial tab afterwards.
TabControlEx keeps the visual tree of every tab in memory once it has been selected. The regular TabControl only keeps the currently selected tabs content in memory and unloads the content from unselected tabs.
Hope this helps.

@batzen batzen self-assigned this May 14, 2020
@batzen batzen added the Question ❓ Not an issue but a question instead. label May 14, 2020
@845669495
Copy link
Author

But WPF native controls do not have this problem. Is there any difference between Ribbon and native controls?

@batzen
Copy link
Member

batzen commented May 15, 2020

Do you have a sample where regular wpf controls don't have this issue?

@batzen batzen reopened this May 15, 2020
@845669495
Copy link
Author

<TabControl>
    <TabItem Header="tab1" IsSelected="True">
    </TabItem>
    <TabItem Header="tab2">
        <StackPanel>
            <CheckBox x:Name="cb1">checkBox1</CheckBox>
            <CheckBox x:Name="cb2" IsChecked="{Binding ElementName=cb1,Path=IsChecked}">checkBox2</CheckBox>
            <Fluent:Ribbon>
                <Fluent:RibbonTabItem Header="Main">
                    <Fluent:RibbonGroupBox>
                        <CheckBox x:Name="cb3" IsChecked="{Binding ElementName=cb1,Path=IsChecked}">checkBox3</CheckBox>
                    </Fluent:RibbonGroupBox>
                </Fluent:RibbonTabItem>
            </Fluent:Ribbon>
        </StackPanel>
    </TabItem>
</TabControl>

The above is the example code. The data binding of checkBox1 and checkBox2 can work, but the data binding of checkBox1 and checkBox3 does not work.

The following is the output log
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'ElementName=cb1'. BindingExpression:Path=IsChecked; DataItem=null; target element is 'CheckBox' (Name='cb3'); target property is 'IsChecked' (type 'Nullable`1')

@845669495
Copy link
Author

666

@batzen
Copy link
Member

batzen commented May 16, 2020

Will have a look at this when i find some spare time.

@batzen batzen added Bug 🐞 and removed Question ❓ Not an issue but a question instead. labels May 21, 2020
@batzen batzen added this to the 8.0.0 milestone May 21, 2020
batzen added a commit that referenced this issue May 28, 2020
@batzen
Copy link
Member

batzen commented Jun 12, 2020

This is fixed in version 8.0.

@batzen batzen closed this as completed Jun 12, 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