让一个ComboBox在WPF中闪烁

时间:2017-05-08 10:25:44

标签: c# wpf xaml combobox storyboard

我在MVVM应用程序中有一个简单的ComboBox ComboBox内部的重要内容如下所示:

declare @Price int = 0
select format(@Price, 'N') --General format
select format(@Price, 'C') --Currency format

我改变了ToggleButton的XAML样式(在ComboBox样式定义中),如下所示:

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

(我从原始样式中取出了大部分定义,只将<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}"。 之后,我可以使用XAML中的Background属性来按照预期更改ComboBox的颜色,但我需要触发StoryBoard,以便我可以让ComboBox“闪烁”。通过编程手段 一旦我启动故事板,应用程序崩溃(计时器不再工作,依此类推)没有错误信息。
谁知道我错过了什么?

0 个答案:

没有答案