Closed 845669495 closed 4 years ago
<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.
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.
But WPF native controls do not have this problem. Is there any difference between Ribbon and native controls?
Do you have a sample where regular wpf controls don't have this issue?
<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')
Will have a look at this when i find some spare time.
This is fixed in version 8.0.
Conditions that trigger bugs:
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