Programmatically Setting ControlTemplate Item

Posted by Robert on Stack Overflow See other posts from Stack Overflow or by Robert
Published on 2010-06-06T20:38:47Z Indexed on 2010/06/06 20:42 UTC
Read the original article Hit count: 251

Filed under:
|

I'm having trouble figuring out how to programmatically setting the "Stroke" of my arrow. I'm using these buttons in a menu bar and I want the one currently selected to have it's arrow change to green and all the others gray.

    <Style x:Key="FooterGrayButtonStyle" TargetType="{x:Type Button}">  
    <Setter Property="HorizontalContentAlignment" Value="Center"/>
    <Setter Property="VerticalContentAlignment" Value="Center"/>
    <Setter Property="MinHeight" Value="35" />
    <Setter Property="FontSize" Value="16"/>
    <Setter Property="Margin" Value="0,5,10,5" />
    <Setter Property="Foreground" Value="White" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Button}">
                <Grid>
                    <Border x:Name="Bd" Background="#FF535A65" BorderBrush="Black" BorderThickness="1" CornerRadius="10">
                        <Path x:Name="arrow" Stretch="Fill" Stroke="#FFB1BB1C" StrokeThickness="5" HorizontalAlignment="Right" Margin="5" 
                                StrokeEndLineCap="Round" StrokeStartLineCap="Round" StrokeLineJoin="Miter" Width="13" Height="23" Data="M0,0 L1,1 0,2" />
                    </Border>
                    <ContentPresenter HorizontalAlignment="Left" Margin="15,-2,30,0" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" RecognizesAccessKey="True"/>
                </Grid>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsPressed" Value="True">
                        <Setter TargetName="Bd" Property="Background" Value="#FFB1BB1C" />
                        <Setter Property="Stroke" TargetName="arrow" Value="White"/>
                    </Trigger>
                    <Trigger Property="IsEnabled" Value="False">
                        <Setter Property="Stroke" TargetName="arrow" Value="#FFB7B7B7"/>
                        <Setter Property="Foreground" Value="#FFB7B7B7"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

© Stack Overflow or respective owner

Related posts about c#

Related posts about wpf