0

我有以下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>

如果我设置IsIndeterminateTrueon ProgressBar; 我可以看到Indicator搬进来,designer但看不到runtime。任何人都知道为什么它不起作用runtime

编辑:

使用 Visual Studio Professional 2012 / 应用程序是 WPF .NET 3.5

4

1 回答 1

0

我试过你的例子,它似乎工作。检查:

  1. 正确找到了 StaticResources,我使用黑色而不是 ActiveControlBorderBrush 和绿色而不是 ControlBackground。

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

于 2013-06-26T11:39:38.363 回答