Skip to content

Commit

Permalink
Merge pull request #928 from nishy2000/hotfix-927-reflect-size-to-con…
Browse files Browse the repository at this point in the history
…trols-in-panel

Fix for #927 (RibbonGroupBox size reflection issue)
  • Loading branch information
batzen authored May 13, 2021
2 parents a657b61 + f32b026 commit 6c8189d
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 9 deletions.
84 changes: 84 additions & 0 deletions Fluent.Ribbon.Showcase/TestContent.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2712,6 +2712,90 @@ Pellentesque nec dolor sed lacus tristique rutrum sed vitae urna. Sed eu pharetr
Visibility="Collapsed" />
</Fluent:RibbonTabItem>

<Fluent:RibbonTabItem Header="Ribbon controls in panel"
ReduceOrder="PanelGroup11,PanelGroup12,PanelGroup13,PanelGroup11,PanelGroup12,PanelGroup13,PanelGroup11,PanelGroup12,PanelGroup13,PanelGroup11,PanelGroup12,PanelGroup13"
KeyTip="P">
<Fluent:RibbonGroupBox x:Name="PanelGroup11"
Header="In RibbonToolBar"
LauncherText="launcher"
Icon="pack://application:,,,/Fluent.Ribbon.Showcase;component/Images/Green.png"
IsSeparatorVisible="True"
IsLauncherVisible="True">

<Fluent:RibbonToolBar>
<Fluent:Button Header="Full(L/L/S) button"
Icon="pack://application:,,,/Fluent.Ribbon.Showcase;component/Images/Gray.png"
LargeIcon="pack://application:,,,/Fluent.Ribbon.Showcase;component/Images/GrayLarge.png"
SizeDefinition="Large,Large,Small"/>
<Fluent:Button Header="Full(M/M/S) button"
Icon="pack://application:,,,/Fluent.Ribbon.Showcase;component/Images/Yellow.png"
LargeIcon="pack://application:,,,/Fluent.Ribbon.Showcase;component/Images/YellowLarge.png"
SizeDefinition="Middle,Middle,Small"/>
<Fluent:Button Header="Full(L/L/L) button"
Icon="pack://application:,,,/Fluent.Ribbon.Showcase;component/Images/Orange.png"
LargeIcon="pack://application:,,,/Fluent.Ribbon.Showcase;component/Images/OrangeLarge.png"
SizeDefinition="Large"/>
<Fluent:Button Header="Full(default) button"
Icon="pack://application:,,,/Fluent.Ribbon.Showcase;component/Images/Brown.png"
LargeIcon="pack://application:,,,/Fluent.Ribbon.Showcase;component/Images/BrownLarge.png" />
</Fluent:RibbonToolBar>
</Fluent:RibbonGroupBox>

<Fluent:RibbonGroupBox x:Name="PanelGroup12"
Header="In StackPanel"
Icon="pack://application:,,,/Fluent.Ribbon.Showcase;component/Images/Green.png">
<StackPanel Orientation="Horizontal">
<Fluent:Button Header="Full(L/L/S) button"
Icon="pack://application:,,,/Fluent.Ribbon.Showcase;component/Images/Gray.png"
LargeIcon="pack://application:,,,/Fluent.Ribbon.Showcase;component/Images/GrayLarge.png"
SizeDefinition="Large,Large,Small"/>
<Fluent:Button Header="Full(M/M/S) button"
Icon="pack://application:,,,/Fluent.Ribbon.Showcase;component/Images/Yellow.png"
LargeIcon="pack://application:,,,/Fluent.Ribbon.Showcase;component/Images/YellowLarge.png"
SizeDefinition="Middle,Middle,Small"/>
<Fluent:Button Header="Full(L/L/L) button"
Icon="pack://application:,,,/Fluent.Ribbon.Showcase;component/Images/Orange.png"
LargeIcon="pack://application:,,,/Fluent.Ribbon.Showcase;component/Images/OrangeLarge.png"
SizeDefinition="Large"/>
<Fluent:Button Header="Full(default) button"
Icon="pack://application:,,,/Fluent.Ribbon.Showcase;component/Images/Brown.png"
LargeIcon="pack://application:,,,/Fluent.Ribbon.Showcase;component/Images/BrownLarge.png" />
</StackPanel>
</Fluent:RibbonGroupBox>

<Fluent:RibbonGroupBox x:Name="PanelGroup13"
Header="In Grid"
Icon="pack://application:,,,/Fluent.Ribbon.Showcase;component/Images/Green.png">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Fluent:Button Header="Full(L/L/S) button"
Grid.Column="0"
Icon="pack://application:,,,/Fluent.Ribbon.Showcase;component/Images/Gray.png"
LargeIcon="pack://application:,,,/Fluent.Ribbon.Showcase;component/Images/GrayLarge.png"
SizeDefinition="Large,Large,Small"/>
<Fluent:Button Header="Full(M/M/S) button"
Grid.Column="1"
Icon="pack://application:,,,/Fluent.Ribbon.Showcase;component/Images/Yellow.png"
LargeIcon="pack://application:,,,/Fluent.Ribbon.Showcase;component/Images/YellowLarge.png"
SizeDefinition="Middle,Middle,Small"/>
<Fluent:Button Header="Full(L/L/L) button"
Grid.Column="2"
Icon="pack://application:,,,/Fluent.Ribbon.Showcase;component/Images/Orange.png"
LargeIcon="pack://application:,,,/Fluent.Ribbon.Showcase;component/Images/OrangeLarge.png"
SizeDefinition="Large"/>
<Fluent:Button Header="Full(default) button"
Grid.Column="3"
Icon="pack://application:,,,/Fluent.Ribbon.Showcase;component/Images/Brown.png"
LargeIcon="pack://application:,,,/Fluent.Ribbon.Showcase;component/Images/BrownLarge.png" />
</Grid>
</Fluent:RibbonGroupBox>
</Fluent:RibbonTabItem>

</Fluent:Ribbon>

<TabControl Grid.Row="1"
Expand Down
28 changes: 19 additions & 9 deletions Fluent.Ribbon/Controls/RibbonGroupBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,21 +148,31 @@ private void UpdateChildSizes()
foreach (var item in this.Items)
{
var element = this.ItemContainerGenerator.ContainerFromItem(item);
this.UpdateChildSizesOfUIElement(element, groupBoxState);
}
}

if (element is null)
{
continue;
}

var targetElement = element;
private void UpdateChildSizesOfUIElement(DependencyObject? element, RibbonGroupBoxState groupBoxState)
{
if (element is null)
{
return;
}

if (targetElement is ContentPresenter)
if (element is Panel panel)
{
for (int i = 0; i < panel.Children.Count; i++)
{
targetElement = UIHelper.GetFirstVisualChild(targetElement) ?? targetElement;
this.UpdateChildSizesOfUIElement(panel.Children[i], groupBoxState);
}
}

RibbonProperties.SetAppropriateSize(targetElement, groupBoxState);
if (element is ContentPresenter)
{
element = UIHelper.GetFirstVisualChild(element) ?? element;
}

RibbonProperties.SetAppropriateSize(element, groupBoxState);
}

#endregion
Expand Down

0 comments on commit 6c8189d

Please sign in to comment.