【问题标题】:WPF Theme Error: Cannot resolve all property references in the property pathWPF 主题错误:无法解析属性路径中的所有属性引用
【发布时间】:2014-08-30 17:31:05
【问题描述】:

我在 WPF 主题上遇到了一个奇怪的错误:Cannot resolve all property references in the property path '(0).(1).(2)[0].X' 我已将其追溯到我的进度条主题。

    <Style x:Key="ProgressBarStyle"
       TargetType="{x:Type ProgressBar}">
    <Setter Property="Foreground"
            Value="{StaticResource ProgressBarForegroundBrush}" />
    <Setter Property="Background"
            Value="{StaticResource ProgressBarBackgroundBrush}" />
    <Setter Property="BorderThickness"
            Value="0" />
    <Setter Property="Height"
            Value="6" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type ProgressBar}">
                <Grid x:Name="TemplateRoot"
                      SnapsToDevicePixels="true">
                    <VisualStateManager.VisualStateGroups>
                        <VisualStateGroup x:Name="CommonStates">
                            <VisualState x:Name="Determinate" />
                            <VisualState x:Name="Indeterminate">
                                <Storyboard RepeatBehavior="Forever">
                                    <DoubleAnimation Duration="00:00:.5"
                                                     From="0"
                                                     To="20"
                                                     Storyboard.TargetProperty="(Shape.Fill).(LinearGradientBrush.Transform).(TransformGroup.Children)[0].X"
                                                     Storyboard.TargetName="IndeterminateGradientFill" />
                                    </Storyboard>
                            </VisualState>
                        </VisualStateGroup>
                    </VisualStateManager.VisualStateGroups>
                    <Border x:Name="ProgressBarTrack"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            Background="{TemplateBinding Background}" />
                    <Rectangle x:Name="PART_Track"
                               Margin="{TemplateBinding BorderThickness}" />
                    <Decorator x:Name="PART_Indicator"
                               HorizontalAlignment="Left"
                               Margin="{TemplateBinding BorderThickness}">
                        <Grid x:Name="Foreground">
                            <Rectangle x:Name="Indicator"
                                       Fill="{TemplateBinding Foreground}" />
                        </Grid>
                    </Decorator>
                    <Grid x:Name="IndeterminateRoot"
                          Visibility="Collapsed">
                        <Rectangle x:Name="IndeterminateSolidFill"
                                   Fill="{TemplateBinding Foreground}"
                                   Margin="{TemplateBinding BorderThickness}"
                                   Opacity="1"
                                   RenderTransformOrigin="0.5,0.5"
                                   StrokeThickness="0" />
                        <Rectangle x:Name="IndeterminateGradientFill"
                                   Fill="{StaticResource ProgressBarIndeterminateBackgroundBrush}"
                                   Margin="{TemplateBinding BorderThickness}"
                                   StrokeThickness="1" />
                    </Grid>
                </Grid>
                <ControlTemplate.Triggers>
                    <Trigger Property="Orientation"
                             Value="Vertical">
                        <Setter Property="LayoutTransform"
                                TargetName="TemplateRoot">
                            <Setter.Value>
                                <RotateTransform Angle="-90" />
                            </Setter.Value>
                        </Setter>
                    </Trigger>
                    <Trigger Property="IsIndeterminate"
                             Value="true">
                        <Setter Property="Visibility"
                                TargetName="Indicator"
                                Value="Collapsed" />
                        <Setter Property="Visibility"
                                TargetName="IndeterminateRoot"
                                Value="Visible" />
                    </Trigger>
                    <Trigger Property="IsIndeterminate"
                             Value="false">
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

<SolidColorBrush x:Key="ProgressBarBackgroundBrush"
                 Color="{StaticResource Color_005}" />
<SolidColorBrush x:Key="ProgressBarForegroundBrush"
                 Color="{StaticResource Color_024}" />
<LinearGradientBrush x:Key="ProgressBarIndeterminateBackgroundBrush"
                     EndPoint="0,1"
                     MappingMode="Absolute"
                     SpreadMethod="Repeat"
                     StartPoint="20,1"
                     Opacity="0.8">
    <LinearGradientBrush.Transform>
        <TransformGroup>
            <TranslateTransform X="0" />
            <SkewTransform AngleX="-30" />
        </TransformGroup>
    </LinearGradientBrush.Transform>
    <GradientStop Color="{StaticResource Color_023}"
                  Offset="0.249" />
    <GradientStop Color="{StaticResource Color_024}"
                  Offset=".25" />
    <GradientStop Color="{StaticResource Color_024}"
                  Offset="0.75" />
    <GradientStop Color="{StaticResource Color_023}"
                  Offset="0.751" />
</LinearGradientBrush>

现在从我所见,它是DoubleAnimation.Storyboard.TargetProperty 和对LinearGradientBrush ProgressBarIndeterminateBackgroundBrush 转换的引用。但我的菜鸟对此的理解看起来“还可以”!

【问题讨论】:

    标签: wpf themes


    【解决方案1】:

    我能够重现您的情况,只需将 (Shape.Fill) 更改为 (Rectangle.Fill) 似乎就可以解决我的问题。

    【讨论】:

    • 运行时进度条正常工作,但VS2010仍在抱怨错误。您知道动画部分中使用的那种引用类型是什么吗?我以前没见过。
    猜你喜欢
    • 2010-12-24
    • 1970-01-01
    • 1970-01-01
    • 2014-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-04
    相关资源
    最近更新 更多