Advertisement
Krythic

ScrollViewer WPF Style

Jun 1st, 2021
1,293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 14.77 KB | None | 0 0
  1. <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  2.     <!--
  3.        Define The VerticalScrollBar Thumb Style
  4.    -->
  5.     <Style x:Key="VerticalScrollBarThumbStyle" TargetType="{x:Type Thumb}">
  6.         <Setter Property="IsTabStop" Value="False" />
  7.         <Setter Property="Focusable" Value="False" />
  8.         <Setter Property="Margin" Value="0" />
  9.         <Setter Property="Template">
  10.             <Setter.Value>
  11.                 <ControlTemplate TargetType="{x:Type Thumb}">
  12.                     <Rectangle
  13.                        Name="ellipse"
  14.                        Width="10"
  15.                        Fill="#575757"
  16.                        RadiusX="5"
  17.                        RadiusY="5"
  18.                        Stroke="Transparent" />
  19.                     <ControlTemplate.Triggers>
  20.                         <Trigger Property="IsMouseOver" Value="true">
  21.                             <Setter TargetName="ellipse" Property="Fill" Value="#808080" />
  22.                         </Trigger>
  23.                         <Trigger Property="IsDragging" Value="True">
  24.                             <Setter TargetName="ellipse" Property="Fill" Value="#808080" />
  25.                         </Trigger>
  26.  
  27.                     </ControlTemplate.Triggers>
  28.                 </ControlTemplate>
  29.             </Setter.Value>
  30.         </Setter>
  31.     </Style>
  32.  
  33.     <!--
  34.        Define The HorizontalScrollBar Thumb Style
  35.    -->
  36.     <Style x:Key="HorizontalScrollBarThumbStyle" TargetType="{x:Type Thumb}">
  37.         <Setter Property="IsTabStop" Value="False" />
  38.         <Setter Property="Focusable" Value="False" />
  39.         <Setter Property="Margin" Value="0" />
  40.         <Setter Property="Template">
  41.             <Setter.Value>
  42.                 <ControlTemplate TargetType="{x:Type Thumb}">
  43.                     <Rectangle
  44.                        Name="ellipse"
  45.                        Height="10"
  46.                        Fill="#575757"
  47.                        RadiusX="5"
  48.                        RadiusY="5"
  49.                        Stroke="Transparent" />
  50.                     <ControlTemplate.Triggers>
  51.                         <Trigger Property="IsMouseOver" Value="true">
  52.                             <Setter TargetName="ellipse" Property="Fill" Value="#808080" />
  53.                         </Trigger>
  54.                         <Trigger Property="IsDragging" Value="True">
  55.                             <Setter TargetName="ellipse" Property="Fill" Value="#808080" />
  56.                         </Trigger>
  57.                     </ControlTemplate.Triggers>
  58.                 </ControlTemplate>
  59.             </Setter.Value>
  60.         </Setter>
  61.     </Style>
  62.  
  63.     <!--
  64.        Define The Button Up Style
  65.    -->
  66.     <Style x:Key="ButtonUpStyle" TargetType="{x:Type RepeatButton}">
  67.         <Setter Property="Focusable" Value="False" />
  68.         <Setter Property="Template">
  69.             <Setter.Value>
  70.                 <ControlTemplate TargetType="{x:Type RepeatButton}">
  71.                     <Grid Height="18" Margin="1">
  72.                         <Path
  73.                            Name="Path"
  74.                            HorizontalAlignment="Center"
  75.                            VerticalAlignment="Center"
  76.                            Data="M 0 8 L 8 8 L 4 0 Z"
  77.                            Fill="{DynamicResource GlobalAccentSolidColorBrush}"
  78.                            Stretch="None" />
  79.                     </Grid>
  80.                     <ControlTemplate.Triggers>
  81.                         <Trigger Property="IsMouseOver" Value="true">
  82.                             <Setter TargetName="Path" Property="Fill" Value="{DynamicResource GlobalAccentFeedbackSolidColorBrush}" />
  83.                         </Trigger>
  84.                         <Trigger Property="IsPressed" Value="true">
  85.                             <Setter TargetName="Path" Property="Fill" Value="{DynamicResource GlobalAccentFeedbackSolidColorBrush}" />
  86.                         </Trigger>
  87.                     </ControlTemplate.Triggers>
  88.                 </ControlTemplate>
  89.             </Setter.Value>
  90.         </Setter>
  91.     </Style>
  92.  
  93.     <!--
  94.        Define The Button Down Style
  95.    -->
  96.     <Style x:Key="ButtonDownStyle" TargetType="{x:Type RepeatButton}">
  97.         <Setter Property="Focusable" Value="False" />
  98.         <Setter Property="Template">
  99.             <Setter.Value>
  100.                 <ControlTemplate TargetType="{x:Type RepeatButton}">
  101.                     <Grid Height="18" Margin="1">
  102.                         <Path
  103.                            Name="Path"
  104.                            HorizontalAlignment="Center"
  105.                            VerticalAlignment="Center"
  106.                            Data="M 0 0 L 4 8 L 8 0 Z"
  107.                            Fill="{DynamicResource GlobalAccentSolidColorBrush}"
  108.                            Stretch="None" />
  109.                     </Grid>
  110.                     <ControlTemplate.Triggers>
  111.                         <Trigger Property="IsMouseOver" Value="true">
  112.                             <Setter TargetName="Path" Property="Fill" Value="{DynamicResource GlobalAccentFeedbackSolidColorBrush}" />
  113.                         </Trigger>
  114.                         <Trigger Property="IsPressed" Value="true">
  115.                             <Setter TargetName="Path" Property="Fill" Value="{DynamicResource GlobalAccentFeedbackSolidColorBrush}" />
  116.                         </Trigger>
  117.                     </ControlTemplate.Triggers>
  118.                 </ControlTemplate>
  119.             </Setter.Value>
  120.         </Setter>
  121.     </Style>
  122.  
  123.     <!--
  124.        Define The Button Left Style
  125.    -->
  126.     <Style x:Key="ButtonLeftStyle" TargetType="{x:Type RepeatButton}">
  127.         <Setter Property="Focusable" Value="False" />
  128.         <Setter Property="Template">
  129.             <Setter.Value>
  130.                 <ControlTemplate TargetType="{x:Type RepeatButton}">
  131.                     <Grid Width="18" Margin="1">
  132.                         <Path
  133.                            Name="Path"
  134.                            HorizontalAlignment="Center"
  135.                            VerticalAlignment="Center"
  136.                            Data="M 0 0 L -8 4 L 0 8 Z"
  137.                            Fill="{DynamicResource GlobalAccentSolidColorBrush}"
  138.                            Stretch="None" />
  139.                     </Grid>
  140.                     <ControlTemplate.Triggers>
  141.                         <Trigger Property="IsMouseOver" Value="true">
  142.                             <Setter TargetName="Path" Property="Fill" Value="{DynamicResource GlobalAccentFeedbackSolidColorBrush}" />
  143.                         </Trigger>
  144.                         <Trigger Property="IsPressed" Value="true">
  145.                             <Setter TargetName="Path" Property="Fill" Value="{DynamicResource GlobalAccentFeedbackSolidColorBrush}" />
  146.                         </Trigger>
  147.                     </ControlTemplate.Triggers>
  148.                 </ControlTemplate>
  149.             </Setter.Value>
  150.         </Setter>
  151.     </Style>
  152.  
  153.     <!--
  154.        Define The Button Right Style
  155.    -->
  156.     <Style x:Key="ButtonRightStyle" TargetType="{x:Type RepeatButton}">
  157.         <Setter Property="Focusable" Value="False" />
  158.         <Setter Property="Template">
  159.             <Setter.Value>
  160.                 <ControlTemplate TargetType="{x:Type RepeatButton}">
  161.                     <Grid Width="18" Margin="1">
  162.                         <Path
  163.                            Name="Path"
  164.                            HorizontalAlignment="Center"
  165.                            VerticalAlignment="Center"
  166.                            Data="M 0 0 L 8 4 L 0 8 Z"
  167.                            Fill="{DynamicResource GlobalAccentSolidColorBrush}"
  168.                            Stretch="None" />
  169.                     </Grid>
  170.                     <ControlTemplate.Triggers>
  171.                         <Trigger Property="IsMouseOver" Value="true">
  172.                             <Setter TargetName="Path" Property="Fill" Value="{DynamicResource GlobalAccentFeedbackSolidColorBrush}" />
  173.                         </Trigger>
  174.                         <Trigger Property="IsPressed" Value="true">
  175.                             <Setter TargetName="Path" Property="Fill" Value="{DynamicResource GlobalAccentFeedbackSolidColorBrush}" />
  176.                         </Trigger>
  177.                     </ControlTemplate.Triggers>
  178.                 </ControlTemplate>
  179.             </Setter.Value>
  180.         </Setter>
  181.     </Style>
  182.  
  183.  
  184.     <!--
  185.        Define The ScrollBarPageButton Style
  186.    -->
  187.     <Style x:Key="ScrollBarPageButtonStyle" TargetType="{x:Type RepeatButton}">
  188.         <Setter Property="IsTabStop" Value="False" />
  189.         <Setter Property="Focusable" Value="False" />
  190.         <Setter Property="Template">
  191.             <Setter.Value>
  192.                 <ControlTemplate TargetType="{x:Type RepeatButton}">
  193.                     <Border Background="Transparent" />
  194.                 </ControlTemplate>
  195.             </Setter.Value>
  196.         </Setter>
  197.     </Style>
  198.  
  199.     <!--
  200.        Override The VerticalScrollBar Template
  201.    -->
  202.     <ControlTemplate x:Key="VerticalScrollBar" TargetType="{x:Type ScrollBar}">
  203.         <Grid>
  204.             <Grid.RowDefinitions>
  205.                 <RowDefinition MaxHeight="0" />
  206.                 <RowDefinition Height="*" />
  207.                 <RowDefinition MaxHeight="0" />
  208.             </Grid.RowDefinitions>
  209.             <Grid.Background>
  210.                 <SolidColorBrush Color="Transparent" />
  211.             </Grid.Background>
  212.  
  213.             <Track
  214.                Name="PART_Track"
  215.                Grid.Row="1"
  216.                IsDirectionReversed="True">
  217.                 <Track.DecreaseRepeatButton>
  218.                     <RepeatButton Command="ScrollBar.PageUpCommand" Style="{StaticResource ScrollBarPageButtonStyle}" />
  219.                 </Track.DecreaseRepeatButton>
  220.                 <Track.Thumb>
  221.                     <Thumb Style="{StaticResource VerticalScrollBarThumbStyle}" />
  222.                 </Track.Thumb>
  223.                 <Track.IncreaseRepeatButton>
  224.                     <RepeatButton Command="ScrollBar.PageDownCommand" Style="{StaticResource ScrollBarPageButtonStyle}" />
  225.                 </Track.IncreaseRepeatButton>
  226.             </Track>
  227.  
  228.         </Grid>
  229.     </ControlTemplate>
  230.  
  231.     <!--
  232.        Override The HorizontalScrollBar Template
  233.    -->
  234.     <ControlTemplate x:Key="HorizontalScrollBar" TargetType="{x:Type ScrollBar}">
  235.         <Grid>
  236.             <Grid.ColumnDefinitions>
  237.                 <ColumnDefinition MaxWidth="0" />
  238.                 <ColumnDefinition Width="*" />
  239.                 <ColumnDefinition MaxWidth="0" />
  240.             </Grid.ColumnDefinitions>
  241.             <Grid.Background>
  242.                 <SolidColorBrush Color="Transparent" />
  243.             </Grid.Background>
  244.  
  245.             <Track
  246.                Name="PART_Track"
  247.                Grid.Column="1"
  248.                IsDirectionReversed="False">
  249.                 <Track.DecreaseRepeatButton>
  250.                     <RepeatButton Command="ScrollBar.PageLeftCommand" Style="{StaticResource ScrollBarPageButtonStyle}" />
  251.                 </Track.DecreaseRepeatButton>
  252.                 <Track.Thumb>
  253.                     <Thumb Style="{StaticResource HorizontalScrollBarThumbStyle}" />
  254.                 </Track.Thumb>
  255.                 <Track.IncreaseRepeatButton>
  256.                     <RepeatButton Command="ScrollBar.PageRightCommand" Style="{StaticResource ScrollBarPageButtonStyle}" />
  257.                 </Track.IncreaseRepeatButton>
  258.             </Track>
  259.         </Grid>
  260.     </ControlTemplate>
  261.  
  262.     <!--
  263.        Define The ScrollBar Style
  264.    -->
  265.     <Style TargetType="{x:Type ScrollBar}">
  266.         <Setter Property="SnapsToDevicePixels" Value="True" />
  267.         <Setter Property="OverridesDefaultStyle" Value="true" />
  268.         <Style.Triggers>
  269.             <Trigger Property="Orientation" Value="Vertical">
  270.                 <Setter Property="Width" Value="18" />
  271.                 <Setter Property="Height" Value="Auto" />
  272.                 <Setter Property="Template" Value="{StaticResource VerticalScrollBar}" />
  273.             </Trigger>
  274.             <Trigger Property="Orientation" Value="Horizontal">
  275.                 <Setter Property="Width" Value="Auto" />
  276.                 <Setter Property="Height" Value="18" />
  277.                 <Setter Property="Template" Value="{StaticResource HorizontalScrollBar}" />
  278.             </Trigger>
  279.         </Style.Triggers>
  280.     </Style>
  281.    
  282.     <!--
  283.    
  284.        This style does NOT break RichTextBox Scrolling
  285.    
  286.    -->
  287.  
  288.     <Style TargetType="{x:Type ScrollViewer}">
  289.         <Style.Resources>
  290.             <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent" />
  291.         </Style.Resources>
  292.     </Style>
  293.    
  294.    
  295.     <!--
  296.    
  297.        The Style below breaks Rich Text Box
  298.    
  299.    -->
  300.  
  301.     <!--<Style TargetType="{x:Type ScrollViewer}">
  302.        <Setter Property="CanContentScroll" Value="True"></Setter>
  303.        <Setter Property="PanningMode" Value="Both"></Setter>
  304.        <Setter Property="Template">
  305.            <Setter.Value>
  306.                <ControlTemplate TargetType="{x:Type ScrollViewer}">
  307.                    <Grid>
  308.                        <Grid.ColumnDefinitions>
  309.                            <ColumnDefinition />
  310.                            <ColumnDefinition Width="Auto" />
  311.                        </Grid.ColumnDefinitions>
  312.                        <Grid.RowDefinitions>
  313.                            <RowDefinition />
  314.                            <RowDefinition Height="Auto" />
  315.                        </Grid.RowDefinitions>
  316.                        <ScrollContentPresenter Grid.Column="0" />
  317.                        <ScrollBar
  318.                            x:Name="PART_VerticalScrollBar"
  319.                            Grid.Row="0"
  320.                            Grid.Column="1"
  321.                            Maximum="{TemplateBinding ScrollableHeight}"
  322.                            ViewportSize="{TemplateBinding ViewportHeight}"
  323.                            Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"
  324.                            Value="{TemplateBinding VerticalOffset}" />
  325.                        <ScrollBar
  326.                            x:Name="PART_HorizontalScrollBar"
  327.                            Grid.Row="1"
  328.                            Grid.Column="0"
  329.                            Maximum="{TemplateBinding ScrollableWidth}"
  330.                            Orientation="Horizontal"
  331.                            ViewportSize="{TemplateBinding ViewportWidth}"
  332.                            Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"
  333.                            Value="{TemplateBinding HorizontalOffset}" />
  334.                        --><!--<Rectangle Grid.Row="1" Grid.Column="1" Fill="Red"/>--><!--
  335.                    </Grid>
  336.                </ControlTemplate>
  337.            </Setter.Value>
  338.        </Setter>
  339.    </Style>-->
  340.  
  341. </ResourceDictionary>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement