在WPF

2017-05-08 30 views
0

讓一個ComboBox眨眼我有一個MVVM應用程序中的簡單組合框。
組合框看起來像這裏面的重要的事情:在WPF

<ComboBox Name="EmployeesComboBox" 
       ItemsSource="{Binding EmployeeEntries}" 
       SelectedValuePath="Id" 
       SelectedValue="{Binding Id}" 
       Width="192" FontFamily="Arial" FontSize="12"> 
     <ComboBox.Resources> 
      <Storyboard x:Key="BlinkingStoryboard"> 
       <ColorAnimation Storyboard.TargetProperty="Background.Color" Duration="0:0:2" 
         From="White" To="Yellow" RepeatBehavior="Forever" AutoReverse="True" /> 
      </Storyboard> 
     </ComboBox.Resources> 
    </ComboBox> 

我改變了切換按鈕的XAML甚至風格(組合框樣式定義內)喜歡如下:

<Style x:Key="ComboBoxToggleButton" TargetType="{x:Type ToggleButton}"> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="{x:Type ToggleButton}"> 
       <Border x:Name="templateRoot" 
         BorderBrush="{StaticResource ComboBox.Static.Border}" 
         BorderThickness="{TemplateBinding BorderThickness}" 
         Background="{TemplateBinding Background}" SnapsToDevicePixels="true"> 
        <Border x:Name="splitBorder" 
          BorderBrush="Transparent" BorderThickness="1" 
          HorizontalAlignment="Right" Margin="0" 
          SnapsToDevicePixels="true" 
          Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}"> 
         <Path x:Name="arrow" Data="F1 M 0,0 L 2.667,2.66665 L 5.3334,0 L 5.3334,-1.78168 L 2.6667,0.88501 L0,-1.78168 L0,0 Z" 
           Fill="{StaticResource ComboBox.Static.Glyph}" 
           HorizontalAlignment="Center" Margin="0" 
           VerticalAlignment="Center"/> 
        </Border> 
       </Border> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 

(我把大部分的定義出來的原始風貌,只改變了Background="{StaticResource ComboBox.Static.Background}"Background="{TemplateBinding Background}"
之後,我可以使用背景屬性的XAML內改變組合框的顏色如預期,但我需要網絡連接重新創建StoryBoard,這樣我就可以通過編程方式使ComboBox「閃爍」。
只要我啓動故事板,應用程序崩潰(計時器不再工作,等等),沒有錯誤信息。
任何一個想法我失蹤?

回答

0

你需要去在代碼中的故事板的引用,以便您可以啓動它。見Call a storyboard declared in xaml from c#(當然你的是在組合框的資源中定義的,所以你需要從那裏獲取它)。

編輯:獲取有關故障的更多信息,請啓用WPF跟蹤設置在Visual Studio中的設置 - 調試/輸出窗口,然後在輸出窗口中尋找任何警告/錯誤。

+0

從後面的代碼,我所說的故事板,它被發現,但它不工作。我用一個簡單的故事板'= animationStoryboard(故事板)EmployeesComboBox.FindResource( 「BlinkingStoryboard」);'然後'animationStoryboard.Begin();' –

+1

你需要獲得更多的信息即可;關閉我的腦海,在Visual Studio的設置中啓用WPF的跟蹤設置 - 調試/輸出窗口(或者如果已經啓用,請在輸出窗口中查找任何警告/錯誤)。 –

+0

好的,現在我得到了一個例外,那就是沒有動畫的目標。我將它設置爲Storyboard.TargetName =「ExployeesComboBox」,現在它工作正常。謝謝。請將您的答案更改爲您評論的答案,我可以將其稱爲解決方案;) –