@@ -26,6 +26,11 @@
|
||||
Orientation="{Binding #Orientation.Value}">
|
||||
<Button u:ToolBar.OverflowMode="Never" Content="Button 1" />
|
||||
<u:ToolBarSeparator />
|
||||
<TextBox Width="100" VerticalAlignment="Center"></TextBox>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<RadioButton Content="A" VerticalAlignment="Center"></RadioButton>
|
||||
<RadioButton Content="B" VerticalAlignment="Center"></RadioButton>
|
||||
</StackPanel>
|
||||
<Button u:ToolBar.OverflowMode="AsNeeded" Content="Button 2" />
|
||||
<Button u:ToolBar.OverflowMode="AsNeeded" Content="Button 3" />
|
||||
<ToggleButton Content="Toggle" />
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
<ControlTheme x:Key="{x:Type u:ToolBar}" TargetType="u:ToolBar">
|
||||
<Setter Property="HorizontalAlignment" Value="Left"/>
|
||||
<Setter Property="VerticalAlignment" Value="Top"/>
|
||||
<Setter Property="Background" Value="Transparent"/>
|
||||
<Setter Property="ItemsPanel">
|
||||
<ItemsPanelTemplate>
|
||||
<u:ToolBarPanel />
|
||||
@@ -36,12 +37,14 @@
|
||||
<Setter Property="Template">
|
||||
<ControlTemplate TargetType="u:ToolBar">
|
||||
<Border
|
||||
Padding="2"
|
||||
Margin="0"
|
||||
Name="PART_BackgroundBorder"
|
||||
Padding="{TemplateBinding Padding}"
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
|
||||
VerticalAlignment="{TemplateBinding VerticalAlignment}"
|
||||
CornerRadius="4"
|
||||
Theme="{DynamicResource CardBorder}">
|
||||
CornerRadius="4">
|
||||
<DockPanel LastChildFill="True">
|
||||
<ContentPresenter
|
||||
Name="PART_Header"
|
||||
|
||||
@@ -100,37 +100,50 @@ public class ToolBarPanel: StackPanel
|
||||
|
||||
protected override Size ArrangeOverride(Size finalSize)
|
||||
{
|
||||
Children.Clear();
|
||||
OverflowPanel?.Children.Clear();
|
||||
var logicalChildren = _parent?.GetLogicalChildren().OfType<Control>().ToList();
|
||||
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];
|
||||
if(child is ToolBarSeparator s) s.IsVisible = true;
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user