2014-02-14 39 views
0

我最近剛剛更改爲ToggleButton,因爲他們的工作方式類似RadioButtons,這正是我所需要的。ToggleButton未碰到未選中

我有我的按鈕故事板的動畫,當我點擊它們顯示爲箭頭以顯示在頁面的上是這樣的:

enter image description here

但你可以看到,當我選擇他們倆另一個人保持檢查。

這是我此刻的代碼(其中一個按鈕,另一種是一樣的):

<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> 

MouseUpTimeLineMouseDownTimeLineMouseExitTimeLine是這樣的:

<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

+1

那麼,爲什麼不編輯一個RadioButton模板看起來像這樣你可以指定一個GroupName,只允許一個像你想要的行爲一樣被檢查?在這種意義上,ToggleButton默認情況下並不像RadioButton。 –

+0

@ChrisW。我很抱歉,我甚至不知道你可以編輯模板。我對這一切都很陌生。如果你想回答這個問題,我可以標記你有正確的答案。 – Ben

回答

1

呃不用擔心,每個人在某個時刻都必須是新的東西。無論如何,就像我在評論中所說的那樣。 ToggleButton默認不具備您正在查找的功能。切換到RadioButton,只需將它設計爲看起來像你的按鈕,就可以讓生活更輕鬆地向前邁進,提供你所追求的行爲。

您可以在MSN docs中找到信息和默認模板,使用Blend可以使編輯模板非常簡單,例如,您可以在設計器上放置RadioButton,右鍵單擊它並選擇「編輯模板 - >編輯a複製「將控制模板的副本添加到您的視圖以編輯您的內容。

希望這會有所幫助,如果您遇到任何問題,我們會幫您排序。乾杯