ToolBar ControlTemplates,缺少溢出项和ToolBarTray方向

时间:2017-05-31 20:45:43

标签: c# wpf xaml templates controls

我正在为使用UniformGrid的工具栏编写ControlTemplate,以便为工具栏项提供多个列。到目前为止,似乎即使主要使用默认的ControlTemplate标记(la MSDN Documentation),Overflow进入ToolBarOverflowPanel也不再有效。我试过使用默认的ToolBarOverflowPanel 一个StackPanel,没有效果;可以找到相关的模板snippit here

如何让Overflow正常工作?

此外,在ToolBarTray中放置ToolBar控件时,如何检测和设置" Thumb"," Content"和" Overflow Toggle Button& #34;到他们正确的位置? ToolBar ControlTemplates的文档似乎没有涵盖这一点。

编辑我也很好奇,我怎么能在我的主窗口xaml中绑定UniformGrid的列属性?

编辑2 掌握了处理ToolBarTray的基本方法解决了,只需要为相关的附加属性添加ControlTemplate触发器(Trigger Property =" ToolBarTray.Orientation&#34 ;值="垂直")。还有,谁认真地写下了一个写得很好的问题呢?

<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 个答案:

没有答案