diff --git a/demo/Ursa.Demo/DataTemplates/ToolBarItemTemplateSelector.cs b/demo/Ursa.Demo/DataTemplates/ToolBarItemTemplateSelector.cs
index d32c872..bfd9c76 100644
--- a/demo/Ursa.Demo/DataTemplates/ToolBarItemTemplateSelector.cs
+++ b/demo/Ursa.Demo/DataTemplates/ToolBarItemTemplateSelector.cs
@@ -9,17 +9,22 @@ namespace Ursa.Demo.Converters;
public class ToolBarItemTemplateSelector: IDataTemplate
{
+
public static ToolBarItemTemplateSelector Instance { get; } = new();
public Control? Build(object? param)
{
if (param is null) return null;
+ if (param is ToolBarSeparatorViewModel sep)
+ {
+ return new ToolBarSeparator();
+ }
if (param is ToolBarButtonItemViewModel vm)
{
return new Button()
{
[!ContentControl.ContentProperty] = new Binding() { Path = "Content" },
[!Button.CommandProperty] = new Binding() { Path = "Command" },
- //[!ToolBar.OverflowModeProperty] = new Binding(){ Path = "OverflowMode" }
+ [!ToolBar.OverflowModeProperty] = new Binding(){Path = nameof(ToolBarItemViewModel.OverflowMode)},
};
}
if (param is ToolBarCheckBoxItemViweModel cb)
@@ -28,7 +33,7 @@ public class ToolBarItemTemplateSelector: IDataTemplate
{
[!ContentControl.ContentProperty] = new Binding() { Path = "Content" },
[!ToggleButton.IsCheckedProperty] = new Binding() { Path = "IsChecked" },
- //[!ToolBar.OverflowModeProperty] = new Binding(){ Path = "OverflowMode" }
+ [!ToolBar.OverflowModeProperty] = new Binding(){Path = nameof(ToolBarItemViewModel.OverflowMode)},
};
}
if (param is ToolBarComboBoxItemViewModel combo)
@@ -38,7 +43,7 @@ public class ToolBarItemTemplateSelector: IDataTemplate
[!ContentControl.ContentProperty] = new Binding() { Path = "Content" },
[!SelectingItemsControl.SelectedItemProperty] = new Binding() { Path = "SelectedItem" },
[!ItemsControl.ItemsSourceProperty] = new Binding() { Path = "Items" },
- [ToolBar.OverflowModeProperty] = OverflowMode.Always,
+ [!ToolBar.OverflowModeProperty] = new Binding(){Path = nameof(ToolBarItemViewModel.OverflowMode)},
};
}
return new Button() { Content = "Undefined Item" };
diff --git a/demo/Ursa.Demo/Pages/ToolBarDemo.axaml b/demo/Ursa.Demo/Pages/ToolBarDemo.axaml
index d56843e..0496812 100644
--- a/demo/Ursa.Demo/Pages/ToolBarDemo.axaml
+++ b/demo/Ursa.Demo/Pages/ToolBarDemo.axaml
@@ -18,8 +18,10 @@
DockPanel.Dock="Top"
Header="Hello World">
+
+
-
+
@@ -130,4 +132,23 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Ursa.Themes.Semi/Styles/ToolBar.axaml b/src/Ursa.Themes.Semi/Styles/ToolBar.axaml
new file mode 100644
index 0000000..1e040a8
--- /dev/null
+++ b/src/Ursa.Themes.Semi/Styles/ToolBar.axaml
@@ -0,0 +1,26 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Ursa.Themes.Semi/Styles/_index.axaml b/src/Ursa.Themes.Semi/Styles/_index.axaml
index 8423f00..5f40b0f 100644
--- a/src/Ursa.Themes.Semi/Styles/_index.axaml
+++ b/src/Ursa.Themes.Semi/Styles/_index.axaml
@@ -5,5 +5,6 @@
+
diff --git a/src/Ursa/Controls/ToolBar/ToolBar.cs b/src/Ursa/Controls/ToolBar/ToolBar.cs
index 5c483b7..5259247 100644
--- a/src/Ursa/Controls/ToolBar/ToolBar.cs
+++ b/src/Ursa/Controls/ToolBar/ToolBar.cs
@@ -86,7 +86,11 @@ public class ToolBar: HeaderedItemsControl
{
return c;
}
- return ItemTemplate?.Build(item) ?? new ContentPresenter();
+ if(ItemTemplate is not null && ItemTemplate.Match(item))
+ {
+ return ItemTemplate.Build(item)?? new ContentPresenter();
+ }
+ return new ContentPresenter();
}
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
diff --git a/src/Ursa/Controls/ToolBar/ToolBarPanel.cs b/src/Ursa/Controls/ToolBar/ToolBarPanel.cs
index 36f9dde..cea2ae4 100644
--- a/src/Ursa/Controls/ToolBar/ToolBarPanel.cs
+++ b/src/Ursa/Controls/ToolBar/ToolBarPanel.cs
@@ -116,8 +116,24 @@ public class ToolBarPanel: StackPanel
{
Children.Add(child);
}
+
+ if (child is ToolBarSeparator s)
+ {
+ s.IsVisible = true;
+ }
}
+ var thisLast = this.Children.LastOrDefault();
+ if (thisLast is ToolBarSeparator s2)
+ {
+ s2.IsVisible = false;
+ }
+
+ var thatFirst = OverflowPanel?.Children.FirstOrDefault();
+ if (thatFirst is ToolBarSeparator s3)
+ {
+ s3.IsVisible = false;
+ }
if (_parent != null) _parent.HasOverflowItems = overflow;
return base.ArrangeOverride(finalSize);
}
diff --git a/src/Ursa/Controls/ToolBar/ToolBarSeparator.cs b/src/Ursa/Controls/ToolBar/ToolBarSeparator.cs
new file mode 100644
index 0000000..24a9648
--- /dev/null
+++ b/src/Ursa/Controls/ToolBar/ToolBarSeparator.cs
@@ -0,0 +1,41 @@
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Controls.Metadata;
+using Avalonia.Controls.Primitives;
+using Avalonia.Layout;
+using Avalonia.LogicalTree;
+using Irihi.Avalonia.Shared.Helpers;
+
+namespace Ursa.Controls;
+
+[PseudoClasses(PC_Vertical)]
+public class ToolBarSeparator: TemplatedControl
+{
+ public const string PC_Vertical = ":vertical";
+
+ public static readonly StyledProperty OrientationProperty =
+ ToolBar.OrientationProperty.AddOwner();
+
+ public Orientation Orientation
+ {
+ get => GetValue(OrientationProperty);
+ set => SetValue(OrientationProperty, value);
+ }
+
+ static ToolBarSeparator()
+ {
+ OrientationProperty.OverrideDefaultValue(Orientation.Horizontal);
+ OrientationProperty.Changed.AddClassHandler((separator, args) =>
+ {
+ separator.PseudoClasses.Set(PC_Vertical, args.NewValue.Value == Orientation.Vertical);
+ });
+ }
+
+ protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
+ {
+ base.OnAttachedToLogicalTree(e);
+ var ancestor = this.GetLogicalAncestors().OfType().FirstOrDefault();
+ if (ancestor is null) return;
+ this[!OrientationProperty] = ancestor[!ToolBar.OrientationProperty];
+ }
+}
\ No newline at end of file