2017-02-26 5 views
2

Ich schreibe in C# UWP. ScrollBar Styling funktioniert nicht, aber einige ScrollViewer Styling ist gut.Styling der Bildlaufleiste funktioniert nicht

enter image description here

Mein Code hinter:

 Style ScrollBarStyle = new Style(typeof(ScrollBar)); 
     ScrollBarStyle.Setters.Add(new Setter(ScrollBar.BackgroundProperty, new SolidColorBrush(Colors.Blue))); 

     Style ScrollViewerStyle = new Style(typeof(ScrollViewer)); 
     ScrollViewerStyle.Setters.Add(new Setter(ScrollViewer.BackgroundProperty, new SolidColorBrush(Colors.Blue))); 

     Application.Current.Resources.Add(typeof(ScrollViewer), ScrollViewerStyle); 
     Application.Current.Resources.Add(typeof(ScrollBar), ScrollBarStyle); 

Antwort

4

Ich schreibe in C# UWP. ScrollBar Style ist nicht funktioniert, aber einige Stil ScrollViewer Style ist gut.

Die Farbe von ScrollBar Hintergrund ist Transparent im Standardstil. Und die ScrollBar Hintergrundfarbe wird durch Wurzel Grid abgedeckt. Sie müssen also nur die Hintergrundfarbe des Grundrasters ändern, um die Hintergrundfarbe ScrollBar zu ändern.

Nutzungs

<SolidColorBrush x:Key="ScrollBarBackgroundBrush" Color="Red" /> 
    <SolidColorBrush x:Key="ScrollBarPanningBackgroundBrush" Color="Blue" /> 
    <Style TargetType="ScrollBar"> 
     <Setter Property="MinWidth" Value="7" /> 
     <Setter Property="MinHeight" Value="7" /> 
     <Setter Property="Background" Value="Transparent" /> 
     <Setter Property="Foreground" Value="Transparent" /> 
     <Setter Property="BorderBrush" Value="Transparent" /> 
     <Setter Property="IsTabStop" Value="False" /> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="ScrollBar"> 
        <Grid x:Name="Root" Background="{StaticResource ScrollBarBackgroundBrush}"> 
         <Grid x:Name="HorizontalPanningRoot" MinWidth="53"> 
          <Rectangle 
           x:Name="HorizontalPanningThumb" 
           Height="2.4" 
           MinWidth="7" 
           HorizontalAlignment="Left" 
           AutomationProperties.AccessibilityView="Raw" 
           Fill="{StaticResource ScrollBarPanningBackgroundBrush}" /> 
         </Grid> 
         <Grid x:Name="VerticalPanningRoot" MinHeight="53"> 
          <Rectangle 
           x:Name="VerticalPanningThumb" 
           Width="2.4" 
           MinHeight="7" 
           VerticalAlignment="Top" 
           AutomationProperties.AccessibilityView="Raw" 
           Fill="{StaticResource ScrollBarPanningBackgroundBrush}" /> 
         </Grid> 
         <VisualStateManager.VisualStateGroups> 
          <VisualStateGroup x:Name="CommonStates"> 
           <VisualState x:Name="Normal" /> 
           <VisualState x:Name="PointerOver" /> 
           <VisualState x:Name="Disabled"> 
            <Storyboard> 
             <DoubleAnimation 
              Storyboard.TargetName="Root" 
              Storyboard.TargetProperty="Opacity" 
              To="0.5" 
              Duration="0" /> 
            </Storyboard> 
           </VisualState> 
          </VisualStateGroup> 
          <VisualStateGroup x:Name="ScrollingIndicatorStates"> 
           <VisualState x:Name="TouchIndicator"> 
            <Storyboard> 
             <FadeInThemeAnimation Storyboard.TargetName="HorizontalPanningRoot" /> 
             <FadeInThemeAnimation Storyboard.TargetName="VerticalPanningRoot" /> 
            </Storyboard> 
           </VisualState> 
           <VisualState x:Name="MouseIndicator" /> 
           <VisualState x:Name="NoIndicator"> 
            <Storyboard> 
             <FadeOutThemeAnimation BeginTime="0" Storyboard.TargetName="HorizontalPanningRoot" /> 
             <FadeOutThemeAnimation BeginTime="0" Storyboard.TargetName="VerticalPanningRoot" /> 
            </Storyboard> 
           </VisualState> 
          </VisualStateGroup> 
         </VisualStateManager.VisualStateGroups> 
        </Grid> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 

Stellen Sie die Hintergrundfarbe rot Wurzel Gitter.

enter image description here

+0

Kann es mit C# -Code sein? Ich möchte nur die Farbe der Bildlaufleiste ändern – Naduxa

+1

Es ist nicht einfach, Bildlaufleiste Hintergrundfarbe mit C# -Code zu ändern. Wenn Sie nur die Farbe der Bildlaufleiste ändern möchten. Sie konnten nur die Hintergrundfarbe "root" auf dem Standard [style] ändern (https://msdn.microsoft.com/en-us/library/windows/apps/mt299150.aspx). –

+0

Vielen Dank! – Naduxa

Verwandte Themen