views:

79

answers:

1

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!

A: 

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}"

lukas
s TargetType="typeName" == TargetType="{x:Type typename}"Is that for .net 3.5 or just 4?
dex3703