ToolBar ControlTemplates, Missing Overflow Items, and ToolBarTray Orientation

Viewed 217

I'm writing a ControlTemplate for toolbars that utilizes a UniformGrid in order to provide multiple columns for toolbar items. So far, it seems that even with mostly default ControlTemplate markup (a la MSDN Documentation), Overflow into the ToolBarOverflowPanel no longer works. I have tried using both the default ToolBarOverflowPanel and a StackPanel, to no effect; the relevant template snippit can be found here.

How do I get Overflow to work properly?

Additionally, when placing a ToolBar control inside a ToolBarTray, how can I detect and set the "Thumb", "Content", and "Overflow Toggle Button" to their correct positions? The documentation for ToolBar ControlTemplates does not seem to cover this.

edit: Also something I'm curious about, how can I tie into the UniformGrid's Column property in my Main window xaml?

edit 2: Got the basic for dealing with ToolBarTray Orientation resolved, just needed to add ControlTemplate triggers for the related attached properties (Trigger Property="ToolBarTray.Orientation" Value="Vertical"). Also, who downvotes a decently written question, seriously?

<ToggleButton DockPanel.Dock="Right" 
    ClickMode="Press"
    IsChecked="{Binding 
        IsOverflowOpen, 
        Mode=TwoWay, 
        RelativeSource={RelativeSource TemplatedParent}
    }" 
    IsEnabled="{TemplateBinding HasOverflowItems}" 
>
    <ToggleButton.Template>
        <ControlTemplate TargetType="{x:Type ToggleButton}">
            <Border x:Name="Border"
                Background="{StaticResource 
                    {x:Static SystemColors.MenuBarBrushKey}
                }" 
                CornerRadius="0,3,3,0" 
                SnapsToDevicePixels="true" 
            >
                <Grid>
                    <Path x:Name="Arrow" 
                        Data="M -0.5 3 L 5.5 3 L 2.5 6 Z" 
                        Fill="{StaticResource {x:Static 
                            SystemColors.ControlTextBrushKey
                        }}" 
                        Margin="2,3" 
                        VerticalAlignment="Bottom" 
                    />
                    <ContentPresenter />
                </Grid>
            </Border>
        </ControlTemplate>
    </ToggleButton.Template>
    <Popup x:Name="OverflowPopup" 
        AllowsTransparency="true" 
        Focusable="false" 
        IsOpen="{Binding 
            IsOverflowOpen, 
            RelativeSource={RelativeSource TemplatedParent}
        }" 
        Placement="Bottom" 
        PopupAnimation="Slide" 
        StaysOpen="false" 
    >
        <Border x:Name="DropDownBorder"
            Background="{StaticResource 
                {x:Static SystemColors.MenuBarBrushKey}
            }" 
            BorderBrush="{StaticResource 
                {x:Static SystemColors.ControlDarkBrushKey}
            }" 
            BorderThickness="1"
        >
            <StackPanel x:Name="PART_ToolBarOverflowPanel" 
                Focusable="true" 
                FocusVisualStyle="{x:Null}" 
                KeyboardNavigation.TabNavigation="Cycle" 
                KeyboardNavigation.DirectionalNavigation="Cycle" 
                Margin="2" 
            />
            <!--<ToolBarOverflowPanel 
                x:Name="PART_ToolBarOverflowPanel" 
                Focusable="true" 
                FocusVisualStyle="{x:Null}" 
                KeyboardNavigation.TabNavigation="Cycle" 
                KeyboardNavigation.DirectionalNavigation="Cycle" 
                Margin="2" 
                WrapWidth="200" 
            />-->
        </Border>
    </Popup>
</ToggleButton>
0 Answers
Related