diff --git a/demo/Ursa.Demo/Pages/ToolBarDemo.axaml b/demo/Ursa.Demo/Pages/ToolBarDemo.axaml
index b00fc45..c852b9c 100644
--- a/demo/Ursa.Demo/Pages/ToolBarDemo.axaml
+++ b/demo/Ursa.Demo/Pages/ToolBarDemo.axaml
@@ -26,6 +26,11 @@
Orientation="{Binding #Orientation.Value}">
+
+
+
+
+
diff --git a/src/Ursa/Controls/ToolBar/ToolBarPanel.cs b/src/Ursa/Controls/ToolBar/ToolBarPanel.cs
index cea2ae4..df3971d 100644
--- a/src/Ursa/Controls/ToolBar/ToolBarPanel.cs
+++ b/src/Ursa/Controls/ToolBar/ToolBarPanel.cs
@@ -100,37 +100,53 @@ public class ToolBarPanel: StackPanel
protected override Size ArrangeOverride(Size finalSize)
{
- Children.Clear();
- OverflowPanel?.Children.Clear();
+ //Children.Clear();
+ //OverflowPanel?.Children.Clear();
var logicalChildren = _parent?.GetLogicalChildren().OfType().ToList();
+ List thisPanel = new List();
+ List thatPanel = new List();
if(logicalChildren is null) return finalSize;
bool overflow = false;
- foreach (var child in logicalChildren)
+ for (int i = 0; i < logicalChildren.Count; i++)
{
- if (ToolBar.GetIsOverflowItem(child))
+ var child = logicalChildren[i];
+ var isItemOverflow = ToolBar.GetIsOverflowItem(child);
+ if(isItemOverflow) overflow = true;
+ if (Children?.Contains(child) == true)
{
- OverflowPanel?.Children.Add(child);
- overflow = true;
+ if (isItemOverflow)
+ {
+ Children.Remove(child);
+ var overflowIndex = -1;
+ if (i > 1)
+ {
+ var last = logicalChildren[i - 1];
+ overflowIndex = OverflowPanel?.Children?.IndexOf(last) ?? -1;
+ }
+ OverflowPanel?.Children?.Insert(overflowIndex + 1, child);
+ }
}
- else
+ else if (OverflowPanel?.Children?.Contains(child) == true)
{
- Children.Add(child);
- }
-
- if (child is ToolBarSeparator s)
- {
- s.IsVisible = true;
+ if (!isItemOverflow)
+ {
+ OverflowPanel.Children.Remove(child);
+ var index = -1;
+ if (i > 1)
+ {
+ var last = logicalChildren[i - 1];
+ index = Children?.IndexOf(last) ?? -1;
+ }
+ Children?.Insert(index + 1, child);
+ }
}
}
-
- var thisLast = this.Children.LastOrDefault();
- if (thisLast is ToolBarSeparator s2)
+
+ if (this.Children?.LastOrDefault() is ToolBarSeparator s2)
{
s2.IsVisible = false;
}
-
- var thatFirst = OverflowPanel?.Children.FirstOrDefault();
- if (thatFirst is ToolBarSeparator s3)
+ if (OverflowPanel?.Children?.FirstOrDefault() is ToolBarSeparator s3)
{
s3.IsVisible = false;
}