akoimeexx

ToolBar ToggleButton/Panel for Overflow Items

May 31st, 2017
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 8.89 KB | None | 0 0
  1. <ResourceDictionary
  2.    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3.    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4.    xmlns:local="clr-namespace:TestToolBarTemplateProject.resources"
  5. >
  6.     <!-- DONE: ToolBar Grip (ToolBarThumb) Template -->
  7.     <ControlTemplate x:Key="UniformGridToolBarThumb"
  8.        TargetType="{x:Type Thumb}"
  9.    >
  10.         <Border
  11.            SnapsToDevicePixels="True"
  12.        >
  13.             <Rectangle
  14.                Margin="3,2"
  15.                MinHeight="4"
  16.                MinWidth="4"
  17.            >
  18.                 <Rectangle.Fill>
  19.                     <DrawingBrush
  20.                        TileMode="Tile"
  21.                        Viewbox="0,0,8,8"
  22.                        ViewboxUnits="Absolute"
  23.                        Viewport="0,0,4,4"
  24.                        ViewportUnits="Absolute"
  25.                    >
  26.                         <DrawingBrush.Drawing>
  27.                             <DrawingGroup>
  28.                                 <GeometryDrawing
  29.                                    Brush="{StaticResource
  30.                                        {x:Static SystemColors.ControlDarkDarkBrushKey}
  31.                                    }"
  32.                                    Geometry="M 4 4 L 4 8 L 8 8 L 8 4 z"
  33.                                />
  34.                             </DrawingGroup>
  35.                         </DrawingBrush.Drawing>
  36.                     </DrawingBrush>
  37.                 </Rectangle.Fill>
  38.             </Rectangle>
  39.         </Border>
  40.     </ControlTemplate>
  41.     <!-- FIXME: OverflowPanel not working -->
  42.     <ControlTemplate x:Key="UniformGridToolBarOverflowButtonTemplate"
  43.        TargetType="{x:Type ToggleButton}"
  44.    >
  45.         <Border x:Name="Border"
  46.            Background="{Binding
  47.                Path=Background,
  48.                RelativeSource={
  49.                    RelativeSource FindAncestor,
  50.                    AncestorType=ToolBar
  51.                }
  52.            }"
  53.            HorizontalAlignment="Right"
  54.            SnapsToDevicePixels="true"
  55.        >
  56.             <Grid>
  57.                 <Path x:Name="Arrow"
  58.                    Data="M -0.5 3 L 5.5 3 L 2.5 6 Z"
  59.                    Fill="{StaticResource {x:Static
  60.                        SystemColors.ControlTextBrushKey
  61.                    }}"
  62.                    Margin="2,3"
  63.                    VerticalAlignment="Bottom"
  64.                />
  65.                 <ContentPresenter />
  66.             </Grid>
  67.         </Border>
  68.         <ControlTemplate.Triggers>
  69.             <DataTrigger
  70.                Binding="{Binding
  71.                    Path=Orientation,
  72.                    RelativeSource={RelativeSource TemplatedParent}
  73.                }"
  74.                Value="Vertical"
  75.            >
  76.                 <Setter TargetName="Arrow"
  77.                    Property="Data"
  78.                    Value="M 3 -0.5 L 3 5.5 L 6 2.5 Z"
  79.                />
  80.             </DataTrigger>
  81.         </ControlTemplate.Triggers>
  82.     </ControlTemplate>
  83.     <!-- FIXME: OverflowPanel not working, UniformGrid.Columns|Rows not working -->
  84.     <ControlTemplate x:Key="UniformGridToolBar"
  85.        TargetType="ToolBar"
  86.    >
  87.         <Border x:Name="Border"
  88.            Background="{Binding
  89.                Path=Background,
  90.                RelativeSource={RelativeSource TemplatedParent}
  91.            }"
  92.            BorderBrush="{Binding
  93.                Path=Border,
  94.                RelativeSource={RelativeSource TemplatedParent}
  95.            }"
  96.            BorderThickness="1"
  97.            CornerRadius="2"
  98.        >
  99.             <DockPanel>
  100.                 <Thumb x:Name="ToolBarThumb"
  101.                    DockPanel.Dock="Left"
  102.                    Cursor="SizeAll"
  103.                    Template="{StaticResource UniformGridToolBarThumb}"
  104.                />
  105.                 <ToggleButton x:Name="OverflowButton"
  106.                    DockPanel.Dock="Right"
  107.                    ClickMode="Press"
  108.                    IsChecked="{Binding
  109.                        IsOverflowOpen,
  110.                        Mode=TwoWay,
  111.                        RelativeSource={RelativeSource TemplatedParent}
  112.                    }"
  113.                    IsEnabled="{TemplateBinding HasOverflowItems}"
  114.                    Template="{StaticResource
  115.                        UniformGridToolBarOverflowButtonTemplate
  116.                    }"
  117.                >
  118.                     <Popup x:Name="OverflowPopup"
  119.                        AllowsTransparency="true"
  120.                        Focusable="false"
  121.                        IsOpen="{Binding
  122.                            IsOverflowOpen,
  123.                            RelativeSource={RelativeSource TemplatedParent}
  124.                        }"
  125.                        Placement="Bottom"
  126.                        PopupAnimation="Slide"
  127.                        StaysOpen="false"
  128.                    >
  129.                         <Border x:Name="DropDownBorder"
  130.                            Background="{Binding
  131.                                Path=Background,
  132.                                RelativeSource={RelativeSource TemplatedParent}
  133.                            }"
  134.                            BorderBrush="{Binding
  135.                                Path=Border,
  136.                                RelativeSource={RelativeSource TemplatedParent}
  137.                            }"
  138.                            BorderThickness="1"
  139.                        >
  140.                             <!--<StackPanel x:Name="PART_ToolBarOverflowPanel"
  141.                                Focusable="true"
  142.                                FocusVisualStyle="{x:Null}"
  143.                                KeyboardNavigation.TabNavigation="Cycle"
  144.                                KeyboardNavigation.DirectionalNavigation="Cycle"
  145.                                Margin="2"
  146.                            />-->
  147.                             <ToolBarOverflowPanel
  148.                                x:Name="PART_ToolBarOverflowPanel"
  149.                                Focusable="true"
  150.                                FocusVisualStyle="{x:Null}"
  151.                                KeyboardNavigation.TabNavigation="Cycle"
  152.                                KeyboardNavigation.DirectionalNavigation="Cycle"
  153.                                Margin="2"
  154.                                WrapWidth="200"
  155.                            />
  156.                         </Border>
  157.                     </Popup>
  158.                 </ToggleButton>
  159.                 <!--<ToolBarPanel x:Name="PART_ToolBarPanel"
  160.                    IsItemsHost="True"
  161.                    Visibility="Collapsed"
  162.                />
  163.                <ItemsControl
  164.                    ItemsSource="{Binding StaticResource PART_ToolBarPanel.Panel}"
  165.                >
  166.                    <ItemsControl.ItemsPanel>
  167.                        <ItemsPanelTemplate>-->
  168.                             <UniformGrid
  169.                                ClipToBounds="True"
  170.                                Columns="{Binding
  171.                                    Path=local:UniformGridToolBarAttachedProperties.ItemColumns,
  172.                                    RelativeSource={RelativeSource TemplatedParent}
  173.                                }"
  174.                                Rows="{Binding
  175.                                    Path=local:UniformGridToolBarAttachedProperties.ItemRows,
  176.                                    RelativeSource={RelativeSource TemplatedParent}
  177.                                }"
  178.                                
  179.                                IsItemsHost="True"
  180.                                Margin="0,1,2,2"
  181.                            />
  182.                         <!--</ItemsPanelTemplate>
  183.                    </ItemsControl.ItemsPanel>
  184.                </ItemsControl>-->
  185.             </DockPanel>
  186.         </Border>
  187.         <ControlTemplate.Triggers>
  188.             <Trigger Property="IsOverflowOpen" Value="true">
  189.                 <Setter TargetName="ToolBarThumb"
  190.                    Property="IsEnabled"
  191.                    Value="false"
  192.                />
  193.             </Trigger>
  194.             <Trigger Property="ToolBarTray.IsLocked" Value="true">
  195.                 <Setter TargetName="ToolBarThumb"
  196.                    Property="Visibility"
  197.                    Value="Collapsed"
  198.                />
  199.             </Trigger>
  200.  
  201.             <Trigger Property="Orientation" Value="Vertical">
  202.                 <Setter TargetName="ToolBarThumb"
  203.                    Property="DockPanel.Dock"
  204.                    Value="Top"
  205.                />
  206.             </Trigger>
  207.             <Trigger Property="Orientation" Value="Vertical">
  208.                 <Setter TargetName="OverflowButton"
  209.                    Property="DockPanel.Dock"
  210.                    Value="Bottom"
  211.                />
  212.             </Trigger>
  213.         </ControlTemplate.Triggers>
  214.     </ControlTemplate>
  215. </ResourceDictionary>
Advertisement
Add Comment
Please, Sign In to add comment