IsIndeterminate ProgressBar模板

时间:2013-06-26 11:17:09

标签: wpf xaml progress-bar

我遵循了ProgressBar样式:

<Style x:Key="{x:Type ProgressBar}" TargetType="{x:Type ProgressBar}">
    <Setter Property="Background" Value="{StaticResource ControlBackground}" />
    <Setter Property="BorderBrush" Value="{StaticResource ActiveControlBorderBrush}" />
    <Setter Property="BorderThickness" Value="1" />
    <Setter Property="FocusVisualStyle" Value="{x:Null}" />
    <Setter Property="MinHeight" Value="23" />
    <Setter Property="MinWidth" Value="75" />
    <Setter Property="OverridesDefaultStyle" Value="True" />
    <Setter Property="SnapsToDevicePixels" Value="True" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type ProgressBar}">
                <Grid MinHeight="{TemplateBinding MinHeight}"
                      MinWidth="{TemplateBinding MinWidth}">
                    <VisualStateManager.VisualStateGroups>
                        <VisualStateGroup x:Name="CommonStates">
                            <VisualState x:Name="Determinate" />
                            <VisualState x:Name="Indeterminate">
                                <Storyboard>
                                    <ObjectAnimationUsingKeyFrames Duration="00:00:00"
                                             Storyboard.TargetName="PART_Indicator"
                                             Storyboard.TargetProperty="Background">
                                        <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                            <DiscreteObjectKeyFrame.Value>
                                                <SolidColorBrush>Transparent</SolidColorBrush>
                                            </DiscreteObjectKeyFrame.Value>
                                        </DiscreteObjectKeyFrame>
                                    </ObjectAnimationUsingKeyFrames>
                                </Storyboard>
                            </VisualState>
                        </VisualStateGroup>
                    </VisualStateManager.VisualStateGroups>
                    <Border x:Name="PART_Track"
                            Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}" />
                    <Border x:Name="PART_Indicator"
                            Background="{TemplateBinding BorderBrush}" 
                            HorizontalAlignment="Left" />
                    <Grid x:Name="Animation" ClipToBounds="True">
                        <Border x:Name="PART_GlowRect"
                                Width="100"
                                Background="{StaticResource ActiveControlBorderBrush}"
                                HorizontalAlignment="Left"
                                Margin="-100,0,0,0" />
                    </Grid>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

如果我在IsIndeterminate上将True设置为ProgressBar;我可以看到Indicator移入designer而不是移到runtime。任何人都知道为什么它不能用于runtime

修改

使用Visual Studio Professional 2012 / Application是WPF .NET 3.5

1 个答案:

答案 0 :(得分:0)

我试过你的例子,它似乎有用。检查:

  1. 找到了StaticResources,我使用的是Black而不是ActiveControlBorderBrush和Green而不是ControlBackground。

  2. 如果您是从代码中显示它,请检查可能存在的线程问题(可能是frezee或smth)。