我有一個奇怪的問題,我希望你能幫助我。按鈕模板 - IsMouseOver在IsPressed執行後停止工作
我創建了一個按鈕的樣式並添加了一些觸發器到模板。 一個用於IsMouseOver和一個用於IsPressed。
兩個觸發器有EnterAction和ExitAction動畫模板的背景色。
當我只是將鼠標懸停在按鈕上時,我可以看到顏色變化,但後我點擊按鈕懸停觸發器停止工作。
下面是一個例子代碼:
<Button Margin="142,130,214,138" Content="Hi Mum!">
<Button.Resources>
<Color x:Key="backgroundColor" A="255" R="52" G="152" B="219" />
<Color x:Key="hoverBackgroundColor" A="255" R="62" G="182" B="255" />
<Color x:Key="pressedBackgroundColor" A="255" R="42" G="122" B="175" />
</Button.Resources>
<Button.Style>
<Style TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="6">
<Border.Background>
<SolidColorBrush x:Name="backgroundBrush" Color="{StaticResource backgroundColor}" />
</Border.Background>
<ContentPresenter ContentTemplate="{TemplateBinding ContentTemplate}"
Content="{TemplateBinding Content}"
ContentStringFormat="{TemplateBinding ContentStringFormat}"
Focusable="False"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
Margin="{TemplateBinding Padding}"
RecognizesAccessKey="True"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<ColorAnimation Storyboard.TargetName="backgroundBrush" Storyboard.TargetProperty="Color" To="{StaticResource hoverBackgroundColor}" Duration="0:0:0.2" />
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<ColorAnimation Storyboard.TargetName="backgroundBrush" Storyboard.TargetProperty="Color" To="{StaticResource backgroundColor}" Duration="0:0:0.2" />
</Storyboard>
</BeginStoryboard>
</Trigger.ExitActions>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<ColorAnimation Storyboard.TargetName="backgroundBrush" Storyboard.TargetProperty="Color" To="{StaticResource pressedBackgroundColor}" Duration="0:0:0.2" />
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<ColorAnimation Storyboard.TargetName="backgroundBrush" Storyboard.TargetProperty="Color" To="{StaticResource backgroundColor}" Duration="0:0:0.2" />
</Storyboard>
</BeginStoryboard>
</Trigger.ExitActions>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Button.Style>
</Button>
franssu,不會不使用'StopStoryboard'對象工作...試試吧。 – Sheridan
@Sheridan自己看.. – franssu
我指的是你的評論,關於改變觸發器的順序,這不起作用......也許我應該更具體。 – Sheridan