我最近剛剛更改爲ToggleButton
,因爲他們的工作方式類似RadioButtons
,這正是我所需要的。ToggleButton未碰到未選中
我有我的按鈕故事板的動畫,當我點擊它們顯示爲箭頭以顯示在頁面的上是這樣的:
但你可以看到,當我選擇他們倆另一個人保持檢查。
這是我此刻的代碼(其中一個按鈕,另一種是一樣的):
<ToggleButton x:Name="btnToDo" Content="Button" HorizontalAlignment="Left" VerticalAlignment="Top" Width="222" Click="Button_Click" Height="29" Margin="0,132,0,0">
<ToggleButton.Template>
<ControlTemplate TargetType="{x:Type ToggleButton}" >
<Grid>
<Image x:Name="Normal" Source="Images/Normal1.png" Width="281" HorizontalAlignment="Left"/>
<Image x:Name="Hover" Source="Images/Hover1.png" Opacity="0" Width="281" HorizontalAlignment="Left"/>
<Image x:Name="Pressed" Source="Images/ben.png" Stretch="Fill" Opacity="0"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="True">
<Trigger.EnterActions>
<BeginStoryboard x:Name="ButtonCheckedStoryboardBegin"
Storyboard="{StaticResource MouseDownTimeLine}"/>
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard x:Name="ButtonUncheckedStoryboardEnd"
Storyboard="{StaticResource MouseUpTimeLine}"/>
</Trigger.ExitActions>
</Trigger>
<Trigger Property="IsChecked" Value="False">
<Trigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource MouseUpTimeLine}"/>
</Trigger.EnterActions>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</ToggleButton.Template>
</ToggleButton>
我MouseUpTimeLine
,MouseDownTimeLine
和MouseExitTimeLine
是這樣的:
<Storyboard x:Key="MouseDownTimeLine" >
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Pressed" Storyboard.TargetProperty="Opacity" >
<SplineDoubleKeyFrame KeyTime="00:00:00.25" Value="1" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Key="MouseUpTimeLine">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Pressed" Storyboard.TargetProperty="Opacity" >
<SplineDoubleKeyFrame KeyTime="00:00:00.25" Value="1"/>
</DoubleAnimationUsingKeyFrames>
<Storyboard x:Key="MouseExitTimeLine">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="Normal" Storyboard.TargetProperty="Opacity" >
<SplineDoubleKeyFrame KeyTime="00:00:00.00" Value="1"/>
</DoubleAnimationUsingKeyFrames>
所以我想在狀態IsChecked
爲False時恢復正常狀態,這應該是另一個按鈕IsChecked
。
那麼,爲什麼不編輯一個RadioButton模板看起來像這樣你可以指定一個GroupName,只允許一個像你想要的行爲一樣被檢查?在這種意義上,ToggleButton默認情況下並不像RadioButton。 –
@ChrisW。我很抱歉,我甚至不知道你可以編輯模板。我對這一切都很陌生。如果你想回答這個問題,我可以標記你有正確的答案。 – Ben