将样式应用于滚动查看器会禁用它

时间:2014-04-04 22:03:48

标签: wpf xaml scrollviewer

对于我的生活,我无法解决问题所在,只要我将此样式应用于滚动查看器,就会绘制垂直滚动条,但看起来它已被禁用。该样式来自wpf xaml。

                  

<Geometry x:Key="ScrollUp">m 3 21.703248 c 0 -0.810665 2.9850856 -4.266337 6.6335237 -7.679272 l 6.6335233 -6.2053359 6.817561 6.7653189 c 3.749658 3.720926 6.559968 7.182113 6.245132 7.691527 C 29.014905 22.7849 25.970346 20.4395 22.564054 17.063485 L 16.370796 10.925277 9.685398 17.05123 C 5.8994898 20.520327 3 22.53793 3 21.703248 z</Geometry>
<Geometry x:Key="ScrollDown">m 3 21.703248 c 0 -0.810665 2.9850856 -4.266337 6.6335237 -7.679272 l 6.6335233 -6.2053359 6.817561 6.7653189 c 3.749658 3.720926 6.559968 7.182113 6.245132 7.691527 C 29.014905 22.7849 25.970346 20.4395 22.564054 17.063485 L 16.370796 10.925277 9.685398 17.05123 C 5.8994898 20.520327 3 22.53793 3 21.703248 z</Geometry>

<Style x:Key="ScrollBarTopButton05" TargetType="{x:Type RepeatButton}" >
    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
    <Setter Property="Height" Value="56" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="RepeatButton">
                <Border x:Name="ButtonTouch" CornerRadius="0" BorderThickness="1" BorderBrush="{StaticResource ButtonLine}" Background="{StaticResource LtBlue}" SnapsToDevicePixels="True" UseLayoutRounding="True" Margin="0" >
                    <Rectangle Width="22" Height="22" StrokeThickness="0" x:Name="IconColor" Margin="4">
                        <Rectangle.Tag>
                            <SolidColorBrush Color="{StaticResource DkBlueColor}" />
                        </Rectangle.Tag>
                        <Rectangle.Fill>
                            <DrawingBrush Stretch="Uniform">
                                <DrawingBrush.Drawing>
                                    <GeometryDrawing Brush="{StaticResource DkBlue}" Geometry="{StaticResource ScrollUp}"/>
                                </DrawingBrush.Drawing>
                            </DrawingBrush>
                        </Rectangle.Fill>
                    </Rectangle>
                </Border>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsPressed" Value="True">
                        <Setter TargetName="ButtonTouch" Property="Background" Value="{StaticResource LtGrey}" />
                    </Trigger>
                    <Trigger Property="IsEnabled" Value="False">
                        <Setter TargetName="IconColor" Property="Visibility" Value="Hidden" />
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

<Style x:Key="ScrollBarBottomButton05" TargetType="{x:Type RepeatButton}" >
    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
    <Setter Property="Height" Value="56" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="RepeatButton">
                <Border x:Name="ButtonTouch" CornerRadius="0" BorderThickness="1" BorderBrush="{StaticResource ButtonLine}" Background="{StaticResource LtBlue}" SnapsToDevicePixels="True" UseLayoutRounding="True" Margin="0" >
                    <Rectangle Width="22" Height="22" StrokeThickness="0" x:Name="IconColor" Margin="4">
                        <Rectangle.Tag>
                            <SolidColorBrush Color="{StaticResource DkBlueColor}" />
                        </Rectangle.Tag>
                        <Rectangle.Fill>
                            <DrawingBrush Stretch="Uniform">
                                <DrawingBrush.Drawing>
                                    <GeometryDrawing Brush="{StaticResource DkBlue}" Geometry="{StaticResource ScrollDown}"/>
                                </DrawingBrush.Drawing>
                            </DrawingBrush>
                        </Rectangle.Fill>
                    </Rectangle>
                </Border>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsPressed" Value="True">
                        <Setter TargetName="ButtonTouch" Property="Background" Value="{StaticResource LtGrey}" />
                    </Trigger>
                    <Trigger Property="IsEnabled" Value="False">
                        <Setter TargetName="IconColor" Property="Visibility" Value="Hidden" />
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

<Style x:Key="ScrollBarPageButton05" TargetType="{x:Type RepeatButton}" >
    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
    <Setter Property="MinHeight" Value="40" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="RepeatButton">
                <Border x:Name="ButtonBorder" CornerRadius="0" BorderThickness="1,0,1,0" BorderBrush="{StaticResource ButtonLine}" SnapsToDevicePixels="True" UseLayoutRounding="True" Margin="0" Background="{StaticResource LtBlue}">
                </Border>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsEnabled" Value="False">
                        <Setter TargetName="ButtonBorder" Property="Background" Value="#C0F7F7F7" />
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

<Style x:Key="ScrollBarThumb05" TargetType="{x:Type Thumb}">
    <Setter Property="SnapsToDevicePixels" Value="True" />
    <Setter Property="OverridesDefaultStyle" Value="true" />
    <Setter Property="IsTabStop" Value="false" />
    <Setter Property="Focusable" Value="false" />
    <Setter Property="Height" Value="56" />
    <Setter Property="Width" Value="30" />
    <Setter Property="HorizontalAlignment" Value="Center" />

    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Thumb}">
                <!--Thumb-->
                <Border x:Name="ScrollThumb" CornerRadius="4" Background="{StaticResource LtBlue}" BorderBrush="{StaticResource ButtonLine}" BorderThickness="1" />
                <ControlTemplate.Triggers>
                    <Trigger Property="IsDragging" Value="True">
                        <Setter TargetName="ScrollThumb" Property="Background" Value="{StaticResource LtGrey}" />
                    </Trigger>
                    <Trigger Property="IsEnabled" Value="False">
                        <Setter TargetName="ScrollThumb" Property="Visibility" Value="Hidden" />
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

<ControlTemplate x:Key="VerticalScrollBar05" TargetType="{x:Type ScrollBar}" >
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="56" />
            <RowDefinition Height="0.00001*" />
            <RowDefinition Height="56" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="50" />
        </Grid.ColumnDefinitions>
        <!--Border around buttons and thumb-->
        <Border Grid.RowSpan="3" CornerRadius="0" Background="{StaticResource LtBlue}" BorderBrush="{StaticResource ButtonLine}" BorderThickness="1" />

        <RepeatButton Grid.Row="0" Height="56" Command="ScrollBar.LineUpCommand" Style="{StaticResource ScrollBarTopButton05}" />

        <Track Name="PART_Track" Grid.Row="1" IsDirectionReversed="true" ViewportSize="NaN" >
            <Track.DecreaseRepeatButton>
                <RepeatButton Command="ScrollBar.PageUpCommand" Style="{StaticResource ScrollBarPageButton05}" />
            </Track.DecreaseRepeatButton>
            <Track.Thumb>
                <Thumb Style="{StaticResource ScrollBarThumb05}" Margin="0,13,0,13" />
            </Track.Thumb>
            <Track.IncreaseRepeatButton>
                <RepeatButton Command="ScrollBar.PageDownCommand" Style="{StaticResource ScrollBarPageButton05}" />
            </Track.IncreaseRepeatButton>
        </Track>

        <RepeatButton Grid.Row="2" Height="56" Command="ScrollBar.LineDownCommand" Style="{StaticResource ScrollBarBottomButton05}" />

    </Grid>
</ControlTemplate>

<Style x:Key="ScrollBar05" TargetType="{x:Type ScrollBar}">
    <Setter Property="SnapsToDevicePixels" Value="True" />
    <Setter Property="OverridesDefaultStyle" Value="true" />
    <Setter Property="Stylus.IsFlicksEnabled" Value="True" />
    <Setter Property="IsEnabled" Value="true" />
    <Style.Triggers>
        <Trigger Property="Orientation" Value="Vertical">
            <Setter Property="Width" Value="56" />
            <Setter Property="Height" Value="Auto" />
            <Setter Property="Template" Value="{StaticResource VerticalScrollBar05}" />
        </Trigger>
    </Style.Triggers>
</Style>

<Style x:Key="ScrollViewer05" TargetType="{x:Type ScrollViewer}">
    <Setter Property="OverridesDefaultStyle" Value="True"/>
    <Setter Property="IsEnabled" Value="true" ></Setter>
    <Setter Property="VerticalScrollBarVisibility" Value="Visible"></Setter>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type ScrollViewer}">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <ScrollContentPresenter Grid.Column="0" Grid.Row="0" />
                    <ScrollBar Name="PART_VerticalScrollBar"
                               Grid.Column="1"
                               Maximum="{TemplateBinding ScrollableHeight}"
                               Orientation="Vertical"
                               Value="{TemplateBinding VerticalOffset}"
                               Style="{DynamicResource ResourceKey=ScrollBar05}"
                               ViewportSize="{TemplateBinding ViewportHeight}"
                               Visibility="Visible" />
                    <ScrollBar Name="PART_HorizontalScrollBar"
                               Grid.Row="1"
                               Grid.Column="0"
                               Maximum="{TemplateBinding ScrollableWidth}"
                               Orientation="Horizontal"
                               Value="{TemplateBinding HorizontalOffset}"
                               ViewportSize="{TemplateBinding ViewportWidth}"
                               Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"/>

                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

<Style x:Key="ScrollViewer05Left" TargetType="{x:Type ScrollViewer}">
    <Setter Property="OverridesDefaultStyle" Value="True"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type ScrollViewer}">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <ScrollContentPresenter Grid.Column="1" Grid.Row="0" />
                    <ScrollBar Name="PART_VerticalScrollBar"
                               Grid.Column="0"
                               Maximum="{TemplateBinding ScrollableHeight}"
                               Orientation="Vertical"
                               Value="{TemplateBinding VerticalOffset}"
                               Style="{DynamicResource ResourceKey=ScrollBar05}"
                               ViewportSize="{TemplateBinding ViewportHeight}"
                               Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}" />
                    <ScrollBar Name="PART_HorizontalScrollBar"
                               Grid.Row="1"
                               Grid.Column="0"
                               Maximum="{TemplateBinding ScrollableWidth}"
                               Orientation="Horizontal"
                               Value="{TemplateBinding HorizontalOffset}"
                               ViewportSize="{TemplateBinding ViewportWidth}"
                               Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"/>

                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

样式通过staticresource bind应用。

<DockPanel Name="mainDock" LastChildFill="True" >
    <local:HeaderControl DockPanel.Dock="Top" Height="100" x:Name="HeaderBar"></local:HeaderControl>
    <local:StatusBarControl DockPanel.Dock="Bottom" Height="56" x:Name="StatusBar"></local:StatusBarControl>
    <DockPanel d:DesignHeight="612" VerticalAlignment="Top" Name="MidDock">
        <StackPanel DockPanel.Dock="left" Name="Leftmenu" Background="{StaticResource MedBlue}" Width="300" d:DesignHeight="612" VerticalAlignment="Stretch"/>
        <ScrollViewer Name="midScroll1" Style="{StaticResource ScrollViewer05}" VerticalScrollBarVisibility="Hidden" d:DesignHeight="612" Width="Auto" CanContentScroll="True" Height="Auto">
            <StackPanel DockPanel.Dock="left" VerticalAlignment="Stretch" Name="Midmenu" Background="{StaticResource LtBlue}" Width="300" CanVerticallyScroll="True">
            </StackPanel>
        </ScrollViewer>
        <StackPanel DockPanel.Dock="right" Name="Metric" Background="White" Width="auto">
            <local:MetricControl Margin="10"></local:MetricControl>
        </StackPanel>
    </DockPanel>

</DockPanel>

谢谢。

2 个答案:

答案 0 :(得分:0)

我不认为它已被禁用,但内容不足以使其滚动。我通过在&#34; Midmenu&#34;中添加1200的高度来实现它。 scrollviewer里面的stackpanel。漂亮的模板,看起来不错,只需要翻转滚动箭头实际指向下方。

enter image description here

答案 1 :(得分:0)

对于那些可能遇到此问题的人

在scrollviewer风格中,它对我有用。