UserControl IsPressed没有提供任何回复

时间:2012-05-08 12:47:41

标签: c# .net wpf xaml user-controls

我在Expression Blend中创建了UserControl(Button)

XAML:

<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="Marica.FullClient.Graphics.Node"
x:Name="UserControl" Height="360" Width="500" Margin="40">

<UserControl.Resources>
    <Style x:Key="ButtonStyle1" TargetType="{x:Type Button}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Button}">
                    <Grid>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal"/>
                                <VisualState x:Name="MouseOver"/>
                                <VisualState x:Name="Pressed">
                                    <Storyboard>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.StrokeThickness)" Storyboard.TargetName="rectangle">
                                            <EasingDoubleKeyFrame KeyTime="0" Value="1"/>
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Disabled"/>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Rectangle x:Name="rectangle" Stroke="Red" Fill="{TemplateBinding Background}"/>
                        <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsFocused" Value="True"/>
                        <Trigger Property="IsDefaulted" Value="True"/>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="StrokeThickness" TargetName="rectangle" Value="13"/>
                        </Trigger>
                        <Trigger Property="IsPressed" Value="True">
                            <Setter Property="StrokeThickness" TargetName="rectangle" Value="13"/>
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="False"/>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</UserControl.Resources>

<Grid x:Name="LayoutRoot">
    <Button Name="NodeButton" Style="{DynamicResource ButtonStyle1}"/>
    <StackPanel Orientation="Vertical">
        <TextBlock
        x:Name="NodeName"
        x:FieldModifier="public"
        Text="Property"
        Margin="8,100,8,8"
        HorizontalAlignment="Center"
        VerticalAlignment="Center"
        TextWrapping="Wrap" 
        TextAlignment="Center"
        FontFamily="Segoe Print"
        FontWeight="Bold" 
        Foreground="White"
        FontSize="50"/>

        <TextBlock
        x:Name="CategoryName"
        x:FieldModifier="public"
        Text="Property"
        Margin="8"
        HorizontalAlignment="Center"
        VerticalAlignment="Center"
        TextWrapping="Wrap" 
        TextAlignment="Center"
        FontFamily="Segoe Print"
        FontWeight="Bold" 
        Foreground="White"
        FontSize="25"/>
    </StackPanel>
</Grid>

当我将它覆盖在控件上时,笔划宽度变大,但是当我点击时,没有任何反应。

1 个答案:

答案 0 :(得分:1)

我希望在IsPressed上你想做Easing动画,它看起来似乎不起作用。嗯,好消息,你的动画很好,你只需要调整它来做你想做的事情,以便看到它实际上正常工作。使用KeyTime和Value

例如,将其更改为:

<EasingDoubleKeyFrame KeyTime="00:00:02" Value="30" />

你将看到它开始工作/做更多