質問

I have a minor issue. We'd like to put as much stylistic items in the styles and outside of the control templates, to make themeing easier. So for the scrollbar's repeatbutton, I can get all of this to work but IsPressed. That only works from the template.

So the template is (basically):

    <ControlTemplate x:Key="ScrollBarButtonCT" TargetType="{x:Type RepeatButton}">
    <Border 
        x:Name="borderRepeatButton"
        Margin="1" 
        CornerRadius="2" 
        Background="{TemplateBinding Background}">
        <Path x:Name="pathArrow"
            HorizontalAlignment="Center"
            VerticalAlignment="Center"
            Fill="{DynamicResource ThumbBrush}"
            Data="{Binding Content, RelativeSource={RelativeSource TemplatedParent}}" />
    </Border>
    <ControlTemplate.Triggers>
        <Trigger Property="IsPressed" Value="true">
            <Setter TargetName="borderRepeatButton" Property="Background" Value="{DynamicResource ThumbPressedBrush}" />
        </Trigger>
    </ControlTemplate.Triggers>
</ControlTemplate>

And the style is

    <Style x:Key="ScrollBarButtonStyle" TargetType="{x:Type RepeatButton}">
    <Setter Property="OverridesDefaultStyle" Value="true"/>
    <Setter Property="Focusable" Value="false"/>
    <Setter Property="IsTabStop" Value="false"/>
    <Setter Property="Background" Value="{DynamicResource ScrollBarBGBrush}"/> <!-- borderRepeatButton -->
    <Setter Property="OpacityMask" Value="{DynamicResource ThumbBrush}"/> <!-- pathArrow-->
    <Setter Property="Template" Value="{StaticResource ScrollBarButtonCT}"/>
    <Style.Triggers>
        <!--<Trigger Property="IsPressed" Value="true">  .... this doesn't work coming from the style
            <Setter Property="Background" Value="{DynamicResource ThumbPressedBrush}" />
        </Trigger>-->
        <Trigger Property="IsEnabled" Value="false">
            <Setter Property="Foreground" Value="{DynamicResource ScrollBarDisabledBGBrush}"/>
        </Trigger>
        <Trigger Property="IsMouseOver" Value="true">
            <Setter Property="Background" Value="{DynamicResource ThumbHoverBrush}"/>
        </Trigger>
    </Style.Triggers>
</Style>

I can't get IsPressed to work from the style. Looking in Snoop IsPressed is raised just fine when using the control. What am I doing wrong? Thanks!

役に立ちましたか?

解決 2

I know this is old, but it turns out this must be a bug in the template. We could never get it to work, and talking to some people on the inside more or less confirmed it. We just left the value in the template and worked around it by swapping templates when we needed a different RepeatButton style.

他のヒント

No idea why it doesnt work, maybe it needs static resource? u can try this to get all styles in one place.

    <Style x:Key="xxxtyle" TargetType="{x:Type Button}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Button}">
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsPressed" Value="True">
                            <Setter Property="Fill" TargetName="rectangle" Value="#FFD5D5D5"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

ps TargetType="typeName" == TargetType="{x:Type typename}"

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top