Xaml 如何获取按钮的颜色值或笔刷?

Xaml 如何获取按钮的颜色值或笔刷?,xaml,windows-phone-7,windows-phone-8,windows-phone,Xaml,Windows Phone 7,Windows Phone 8,Windows Phone,我已经为按钮创建了一个控件模板,用于在按下事件期间更改颜色 我已经创建了一个按钮,模板为 <Button Content="Sample" Height="100" Background="Blue" Foreground="White" BorderBrush="Orange" Template="{StaticResource NewButtonStyle}"/> 模板是 <phone:PhoneApplicationPage.Resource

我已经为按钮创建了一个控件模板,用于在按下事件期间更改颜色

我已经创建了一个按钮,模板为

            <Button Content="Sample" Height="100" Background="Blue" Foreground="White" BorderBrush="Orange" Template="{StaticResource NewButtonStyle}"/>

模板是

<phone:PhoneApplicationPage.Resources>
    <ControlTemplate x:Key="NewButtonStyle" TargetType="Button">
        <Grid Background="Transparent">
            <VisualStateManager.VisualStateGroups>
                <VisualStateGroup x:Name="CommonStates">
                    <VisualState x:Name="Normal"/>
                    <VisualState x:Name="MouseOver"/>
                    <VisualState x:Name="Pressed">
                        <Storyboard>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentContainer" Storyboard.TargetProperty="Foreground">
                                <DiscreteObjectKeyFrame KeyTime="0" Value="White"/>
                            </ObjectAnimationUsingKeyFrames>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PressedHighlightBackground" Storyboard.TargetProperty="Background">
                                <DiscreteObjectKeyFrame KeyTime="0" Value="Red"/>
                            </ObjectAnimationUsingKeyFrames>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ButtonBackground" Storyboard.TargetProperty="BorderBrush">
                                <DiscreteObjectKeyFrame KeyTime="0" Value="Green"/>
                            </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualState>
                    <VisualState x:Name="Disabled">
                        <Storyboard>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentContainer" Storyboard.TargetProperty="Foreground">
                                <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneDisabledBrush}" />
                            </ObjectAnimationUsingKeyFrames>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ButtonBackground" Storyboard.TargetProperty="BorderBrush">
                                <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneDisabledBrush}" />
                            </ObjectAnimationUsingKeyFrames>
                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ButtonBackground" Storyboard.TargetProperty="Background">
                                <DiscreteObjectKeyFrame KeyTime="0" Value="Transparent"/>
                            </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                    </VisualState>
                </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>
            <Border x:Name="ButtonBackground" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="0" Background="{TemplateBinding Background}" Margin="{StaticResource PhoneTouchTargetOverhang}" >
                <Border x:Name="PressedHighlightBackground" Background="Transparent">
                    <ContentControl x:Name="ContentContainer" Foreground="{TemplateBinding Foreground}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Padding="{TemplateBinding Padding}" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}"/>
                </Border>
            </Border>
        </Grid>
    </ControlTemplate>
</phone:PhoneApplicationPage.Resources>

在这里,我所做的是在新闻发布会期间,通过将值设置为一些颜色,我将边框颜色和背景颜色更改为一些其他颜色

但我需要的是,在新闻发布会期间,我需要交换背景和边框的颜色,而不是将值设置为其他颜色。i、 e.应将背景色指定给边框,同样,应将边框颜色指定给背景


请有人帮我实现这一点。

背景和边框笔刷的值是多少?你看过TemplateBinding吗?您需要将其与VisualState一起使用。我尝试使用TemplateBinding。它仅用于指定边框颜色背景,但边框的背景颜色使边框变得透明。