2012-12-06 3 views
0

ScrollViewer에서 Grid를 래핑 할 수 있고 스크롤이 자동으로 작동한다는 것을 알고 있습니다. 그러나 그리드 주위에 스크롤 막대를 만들고 싶습니다. 지금까지, 그리드 주위를 이동할 때 스크롤 막대를 그리드와 동기화했습니다. 그러나 스크롤 막대를 클릭 할 때 스크롤 할 수 있도록 Grid의 속성이나 메서드를 찾을 수 없습니다. SchollViewer가 이미 그렇게하고 있기 때문에 가능하다고 확신합니다. 귀하의 팁을 많이 주시면 감사하겠습니다.WPF : ScrollBar로 그리드를 스크롤하는 방법은 무엇입니까?

업데이트 : 사실 내가 원하는 것은 컨트롤과 같은 Excel 스프레드 시트를 만드는 것입니다. 그리드 레이아웃을 사용하여 스프레드 시트를 만들었고 정상적으로 작동하는 것 같습니다. 그러나 스크롤하는 동안 문제가 발생합니다. Grid 주위에 ScrollViewer를 추가하면 전체 Grid가 스크롤됩니다. 그러나 일부 행이나 열을 스크롤하지 못하게하려고합니다. 또한 ScrollViewer를 사용하면 가로 스크롤 막대가 전체 하단을가립니다. 그러나 Excel과 마찬가지로 몇 가지 탭을 추가 할 수있는 공간을두고 싶습니다. 이 기능은 ScrollViewer의 재구성을 통해 가능합니까?

나는 얼어 붙은 헤더를 얻기 위해 몇 개의 하위 그리드에서 그리드를 분할하는 것을 제안하는 http://social.msdn.microsoft.com/Forums/en/wpf/thread/e495a0cb-0104-4475-8627-3b40cd617fc1에 게시물을 찾습니다. 그러나 열이 많으면 잘 작동하지 않습니다. 또한,이 접근법은 사용자가 고정 영역을 선택할 수 있도록 충분히 유연하지 않습니다. , 당신은 단지 당신이 원하는/필요가없는 비트를 제거하고 등

스크롤 바를 스타일의 색상을 변경할 수

+0

맞춤 스크롤 뷰어를 만드는 이유가 있습니까? –

+0

글쎄, 나는 사용자 정의 스크롤바를 Excel 스크롤바와 비슷하게 만들고 싶다. – newman

+0

WPF, 스크롤바의 스타일을 지정하지만 보길 원합니다. –

답변

0

스타일링 스크롤바는 약간 까다로울 수있다,하지만 난 당신이 시작 (식 스타일의 기준) 얻을 수있는 스타일을 가지고 예 :

<Color x:Key="MainColor">#FF595959</Color> 
<Color x:Key="BlackColor">#FF000000</Color> 
<Color x:Key="WhiteColor">#FFFFFFFF</Color> 

<SolidColorBrush x:Key="NormalBrush" Color="{StaticResource MainColor}" /> 
<SolidColorBrush x:Key="NormalBorderBrush" Color="#FF393939" /> 
<SolidColorBrush x:Key="GlyphBrush" Color="#FFD1D1D1" /> 

<LinearGradientBrush x:Key="PressedBrush" EndPoint="0.5,0.971" StartPoint="0.5,0.042"> 
    <GradientStop Color="#4C000000" Offset="0" /> 
    <GradientStop Color="#26FFFFFF" Offset="1" /> 
    <GradientStop Color="#4C000000" Offset="0.467" /> 
    <GradientStop Color="#26FFFFFF" Offset="0.479" /> 
</LinearGradientBrush> 


<Style TargetType="{x:Type RepeatButton}" BasedOn="{x:Null}"> 
    <Setter Property="Background" Value="{DynamicResource NormalBrush}" /> 
    <Setter Property="BorderBrush" Value="{DynamicResource NormalBorderBrush}" /> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="{x:Type RepeatButton}"> 
       <ControlTemplate.Resources> 
        <Storyboard x:Key="HoverOn"> 
         <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="(UIElement.Opacity)"> 
          <SplineDoubleKeyFrame KeyTime="00:00:00.1000000" Value="0.8"/> 
         </DoubleAnimationUsingKeyFrames> 
        </Storyboard> 
        <Storyboard x:Key="HoverOff"> 
         <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="(UIElement.Opacity)"> 
          <SplineDoubleKeyFrame KeyTime="00:00:00.3000000" Value="0.3"/> 
         </DoubleAnimationUsingKeyFrames> 
        </Storyboard> 
        <Storyboard x:Key="PressedOn"> 
         <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="(UIElement.Opacity)"> 
          <SplineDoubleKeyFrame KeyTime="00:00:00.1000000" Value="0.1"/> 
         </DoubleAnimationUsingKeyFrames> 
        </Storyboard> 
        <Storyboard x:Key="PressedOff"> 
         <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="(UIElement.Opacity)"> 
          <SplineDoubleKeyFrame KeyTime="00:00:00.3000000" Value="0.3"/> 
         </DoubleAnimationUsingKeyFrames> 
        </Storyboard> 
       </ControlTemplate.Resources> 
       <Grid> 
        <Border x:Name="Border" BorderThickness="{TemplateBinding BorderThickness}" Opacity="1" /> 
        <ContentPresenter HorizontalAlignment="Center" x:Name="ContentPresenter" VerticalAlignment="Center" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}" Opacity="0.3" Height="Auto" /> 
       </Grid> 
       <ControlTemplate.Triggers> 
        <Trigger Property="IsKeyboardFocused" Value="true" /> 
        <Trigger Property="IsMouseOver" Value="true"> 
         <Trigger.ExitActions> 
          <BeginStoryboard Storyboard="{StaticResource HoverOff}" x:Name="HoverOff_BeginStoryboard"/> 
         </Trigger.ExitActions> 
         <Trigger.EnterActions> 
          <BeginStoryboard Storyboard="{StaticResource HoverOn}"/> 
         </Trigger.EnterActions> 
        </Trigger> 
        <Trigger Property="IsPressed" Value="true"> 
         <Trigger.ExitActions> 
          <BeginStoryboard Storyboard="{StaticResource PressedOff}" x:Name="PressedOff_BeginStoryboard"/> 
         </Trigger.ExitActions> 
         <Trigger.EnterActions> 
          <BeginStoryboard Storyboard="{StaticResource PressedOn}" x:Name="PressedOn_BeginStoryboard"/> 
         </Trigger.EnterActions> 
        </Trigger> 
        <Trigger Property="IsEnabled" Value="false"> 
         <Setter Property="Opacity" TargetName="ContentPresenter" Value="0.1"/> 
        </Trigger> 
       </ControlTemplate.Triggers> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 

<Style x:Key="NuclearThumbStyle" TargetType="{x:Type Thumb}" BasedOn="{x:Null}"> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="{x:Type Thumb}"> 
       <ControlTemplate.Resources> 
        <Storyboard x:Key="HoverOn"> 
         <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="HoverRectangle" Storyboard.TargetProperty="(UIElement.Opacity)"> 
          <SplineDoubleKeyFrame KeyTime="00:00:00.1000000" Value="0.8"/> 
         </DoubleAnimationUsingKeyFrames> 
        </Storyboard> 
        <Storyboard x:Key="HoverOff"> 
         <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="HoverRectangle" Storyboard.TargetProperty="(UIElement.Opacity)"> 
          <SplineDoubleKeyFrame KeyTime="00:00:00.3000000" Value="0.3"/> 
         </DoubleAnimationUsingKeyFrames> 
        </Storyboard> 
        <Storyboard x:Key="PressedOn"> 
         <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="PressedRectangle" Storyboard.TargetProperty="(UIElement.Opacity)"> 
          <SplineDoubleKeyFrame KeyTime="00:00:00.1000000" Value="0.1"/> 
         </DoubleAnimationUsingKeyFrames> 
        </Storyboard> 
        <Storyboard x:Key="PressedOff"> 
         <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="PressedRectangle" Storyboard.TargetProperty="(UIElement.Opacity)"> 
          <SplineDoubleKeyFrame KeyTime="00:00:00.3000000" Value="0.3"/> 
         </DoubleAnimationUsingKeyFrames> 
        </Storyboard> 
       </ControlTemplate.Resources> 
       <Grid Margin="0,0,0,0" x:Name="Grid"> 
        <Rectangle HorizontalAlignment="Stretch" x:Name="HoverRectangle" VerticalAlignment="Stretch" Width="Auto" Height="Auto" RadiusX="3" RadiusY="4" Stroke="{x:Null}" Margin="4.5,-2,4.5,-2" Opacity="0.3" MinHeight="10"> 
         <Rectangle.Fill> 
          <SolidColorBrush Color="{DynamicResource WhiteColor}" /> 
         </Rectangle.Fill> 
        </Rectangle> 
        <Rectangle HorizontalAlignment="Stretch" x:Name="PressedRectangle" VerticalAlignment="Stretch" Width="Auto" Height="Auto" RadiusX="3" RadiusY="4" Stroke="{x:Null}" Margin="4.5,-2,4.5,-2" Opacity="0.3" MinHeight="10"> 
         <Rectangle.Fill> 
          <SolidColorBrush Color="{DynamicResource WhiteColor}" /> 
         </Rectangle.Fill> 
        </Rectangle> 
       </Grid> 
       <ControlTemplate.Triggers> 
        <Trigger Property="IsFocused" Value="True" /> 
        <Trigger Property="IsMouseOver" Value="True"> 
         <Trigger.ExitActions> 
          <BeginStoryboard Storyboard="{StaticResource HoverOff}" x:Name="HoverOff_BeginStoryboard"/> 
         </Trigger.ExitActions> 
         <Trigger.EnterActions> 
          <BeginStoryboard Storyboard="{StaticResource HoverOn}"/> 
         </Trigger.EnterActions> 
        </Trigger> 
        <Trigger Property="IsEnabled" Value="False" > 
         <Setter Property="Opacity" TargetName="Grid" Value="0.1"/> 
        </Trigger> 
        <Trigger Property="IsDragging" Value="True"> 
         <Trigger.ExitActions> 
          <BeginStoryboard Storyboard="{StaticResource PressedOff}" x:Name="PressedOff_BeginStoryboard"/> 
         </Trigger.ExitActions> 
         <Trigger.EnterActions> 
          <BeginStoryboard Storyboard="{StaticResource PressedOn}" x:Name="PressedOn_BeginStoryboard"/> 
         </Trigger.EnterActions> 
        </Trigger> 
       </ControlTemplate.Triggers> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 

<Style x:Key="NuclearScrollRepeatButtonStyle" TargetType="{x:Type RepeatButton}"> 
    <Setter Property="Background" Value="Transparent" /> 
    <Setter Property="BorderBrush" Value="Transparent" /> 
    <Setter Property="IsTabStop" Value="false" /> 
    <Setter Property="Focusable" Value="false" /> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="{x:Type RepeatButton}"> 
       <Grid> 
        <Rectangle Fill="{TemplateBinding Background}" Stroke="{TemplateBinding BorderBrush}" StrokeThickness="{TemplateBinding BorderThickness}" /> 
       </Grid> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 

<Style TargetType="{x:Type ScrollBar}"> 
    <Setter Property="Stylus.IsFlicksEnabled" Value="false" /> 
    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" /> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="{x:Type ScrollBar}"> 
       <Grid x:Name="GridRoot" Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" Background="{DynamicResource NormalBrush}"> 
        <Grid.RowDefinitions> 
         <RowDefinition MaxHeight="18" /> 
         <RowDefinition Height="0.00001*" /> 
         <RowDefinition MaxHeight="18" /> 
        </Grid.RowDefinitions> 
        <RepeatButton x:Name="DecreaseRepeat" Command="ScrollBar.LineUpCommand" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="{x:Null}"> 
         <Grid Margin="0,0,0,0"> 
          <Path Margin="4.742,3.997,4.946,5.327" VerticalAlignment="Stretch" Height="Auto" Fill="{DynamicResource GlyphBrush}" Stretch="Fill" Stroke="{DynamicResource GlyphBrush}" StrokeThickness="1" Data="M5.2422477,11.132184 L11.5544,11.132184 8.6412958,4.4969033 z" x:Name="DecreaseArrow" /> 
         </Grid> 
        </RepeatButton> 
        <Track Grid.Row="1" x:Name="PART_Track" Orientation="Vertical" IsDirectionReversed="true"> 
         <Track.Thumb> 
          <Thumb Style="{DynamicResource NuclearThumbStyle}" Background="{x:Null}" Foreground="{x:Null}" /> 
         </Track.Thumb> 
         <Track.IncreaseRepeatButton> 
          <RepeatButton x:Name="PageUp" Style="{DynamicResource NuclearScrollRepeatButtonStyle}" Command="ScrollBar.PageDownCommand" /> 
         </Track.IncreaseRepeatButton> 
         <Track.DecreaseRepeatButton> 
          <RepeatButton x:Name="PageDown" Style="{DynamicResource NuclearScrollRepeatButtonStyle}" Command="ScrollBar.PageUpCommand" /> 
         </Track.DecreaseRepeatButton> 
        </Track> 
        <RepeatButton Grid.Row="2" x:Name="IncreaseRepeat" Command="ScrollBar.LineDownCommand"> 
         <Grid> 
          <Path Margin="4.742,3.997,4.946,5.327" x:Name="IncreaseArrow" VerticalAlignment="Stretch" Height="Auto" Fill="{DynamicResource GlyphBrush}" Stretch="Fill" Stroke="{DynamicResource GlyphBrush}" StrokeThickness="1" Data="M5.2422477,11.132184 L11.5544,11.132184 8.6412958,4.4969033 z" RenderTransformOrigin="0.5,0.5"> 
           <Path.RenderTransform> 
            <TransformGroup> 
             <ScaleTransform ScaleX="1" ScaleY="1" /> 
             <SkewTransform AngleX="0" AngleY="0" /> 
             <RotateTransform Angle="180" /> 
             <TranslateTransform X="0" Y="0" /> 
            </TransformGroup> 
           </Path.RenderTransform> 
          </Path> 
         </Grid> 
        </RepeatButton> 
       </Grid> 
       <ControlTemplate.Triggers> 
        <Trigger Property="Orientation" Value="Horizontal"> 
         <Setter Property="LayoutTransform" TargetName="GridRoot"> 
          <Setter.Value> 
           <RotateTransform Angle="-90" /> 
          </Setter.Value> 
         </Setter> 
         <Setter TargetName="PART_Track" Property="Orientation" Value="Vertical" /> 
         <Setter Property="Command" Value="ScrollBar.LineLeftCommand" TargetName="DecreaseRepeat" /> 
         <Setter Property="Command" Value="ScrollBar.LineRightCommand" TargetName="IncreaseRepeat" /> 
         <Setter Property="Command" Value="ScrollBar.PageLeftCommand" TargetName="PageDown" /> 
         <Setter Property="Command" Value="ScrollBar.PageRightCommand" TargetName="PageUp" /> 
        </Trigger> 
       </ControlTemplate.Triggers> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 

스타일 :

,

enter image description here

+0

당신의 스타일에 감사드립니다. 사실, 스크롤바의 모양에 대해 걱정하지 않습니다. 실제로 두 가지 문제가 발생합니다. 1. 그리드의 일부 (예 : 그리드 헤더, 그러나 헤더 이상일 수 있음)의 스크롤을 멈추는 방법. 2. Excel의 탭과 같은 가로 스크롤 막대 옆에 여분의 항목을 추가하는 방법. 그리드 주변의 ScrollViewer를 살펴보면이 두 가지를 수행하는 방법을 알 수 없습니다. – newman

관련 문제