diff --git a/demo/Ursa.Demo/Pages/ToolBarDemo.axaml b/demo/Ursa.Demo/Pages/ToolBarDemo.axaml
index 743ae82..f6fab35 100644
--- a/demo/Ursa.Demo/Pages/ToolBarDemo.axaml
+++ b/demo/Ursa.Demo/Pages/ToolBarDemo.axaml
@@ -10,7 +10,7 @@
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Ursa.Demo.Pages.ToolBarDemo">
-
+
@@ -20,6 +20,5 @@
-
diff --git a/src/Ursa/Controls/ToolBar/ToolBar.cs b/src/Ursa/Controls/ToolBar/ToolBar.cs
index f09437d..08200bc 100644
--- a/src/Ursa/Controls/ToolBar/ToolBar.cs
+++ b/src/Ursa/Controls/ToolBar/ToolBar.cs
@@ -38,10 +38,16 @@ public class ToolBar: HeaderedItemsControl
}
public static readonly AttachedProperty OverflowModeProperty =
- AvaloniaProperty.RegisterAttached("OverflowMode");
+ AvaloniaProperty.RegisterAttached("OverflowMode");
- public static void SetOverflowMode(Control? obj, OverflowMode value) => obj.SetValue(OverflowModeProperty, value);
- public static OverflowMode GetOverflowMode(Control? obj) => obj.GetValue(OverflowModeProperty);
+ public static void SetOverflowMode(Control obj, OverflowMode value) => obj.SetValue(OverflowModeProperty, value);
+ public static OverflowMode GetOverflowMode(Control obj) => obj.GetValue(OverflowModeProperty);
+
+ internal static readonly AttachedProperty IsOverflowItemProperty =
+ AvaloniaProperty.RegisterAttached("IsOverflowItem");
+
+ internal static void SetIsOverflowItem(Control obj, bool value) => obj.SetValue(IsOverflowItemProperty, value);
+ internal static bool GetIsOverflowItem(Control obj) => obj.GetValue(IsOverflowItemProperty);
static ToolBar()
{
diff --git a/src/Ursa/Controls/ToolBar/ToolBarPanel.cs b/src/Ursa/Controls/ToolBar/ToolBarPanel.cs
index 0fd6235..3c25ed9 100644
--- a/src/Ursa/Controls/ToolBar/ToolBarPanel.cs
+++ b/src/Ursa/Controls/ToolBar/ToolBarPanel.cs
@@ -2,7 +2,6 @@
using Avalonia.Controls;
using Avalonia.Layout;
using Avalonia.LogicalTree;
-using Avalonia.VisualTree;
namespace Ursa.Controls;
@@ -45,16 +44,18 @@ public class ToolBarPanel: StackPanel
Size measureSize = availableSize;
bool horizontal = Orientation == Orientation.Horizontal;
bool hasVisibleChildren = false;
- measureSize = horizontal
- ? measureSize.WithWidth(double.PositiveInfinity)
- : measureSize.WithHeight(double.PositiveInfinity);
+ measureSize = new Size(double.PositiveInfinity, double.PositiveInfinity);
int index = 0;
if (logicalChildren is null) return size;
for (int count = logicalChildren.Count; index < count; ++index)
{
Control control = logicalChildren[index];
var mode = ToolBar.GetOverflowMode(control);
- if(mode == OverflowMode.Always) continue;
+ if (mode == OverflowMode.Always)
+ {
+ ToolBar.SetIsOverflowItem(control, true);
+ continue;
+ }
bool isVisible = control.IsVisible;
if (isVisible)
{
@@ -83,6 +84,21 @@ public class ToolBarPanel: StackPanel
protected override Size ArrangeOverride(Size finalSize)
{
+ var logicalChildren = _parent?.GetLogicalChildren().OfType().ToList();
+ Children.Clear();
+ OverflowPanel?.Children.Clear();
+ foreach (var child in logicalChildren)
+ {
+ if (ToolBar.GetIsOverflowItem(child))
+ {
+ OverflowPanel?.Children.Add(child);
+ }
+ else
+ {
+ this.Children.Add(child);
+ }
+ }
+ return base.ArrangeOverride(finalSize);
if (_parent is null)
{
return finalSize;