VS2010中的InvalidOperationException

时间:2010-12-03 18:53:57

标签: wpf

我正在使用Expression Blend 4 + Visual Studio 2010 Pro来创建WPF应用程序。

我已经创建了一个控件样式(或者我应该说模板?)基于CheckBox只使用Blend 4,它完美地运行。但是当我去VS2010时,我得到以下“错误”:

  

'[未知]'属性未指向   路径中的DependencyObject   '(0)(1)[0]。(2)'。

即使我运行应用程序,它也能正常运行。现在,我不需要来修复此错误,但无论如何我想摆脱它。

这是Style的XAML代码:

<Style x:Key="IRSensorCheckBoxStyle" TargetType="{x:Type CheckBox}">
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type CheckBox}">
          <Grid Cursor="Hand">
            <VisualStateManager.VisualStateGroups>
              <VisualStateGroup x:Name="CommonStates">
                <VisualState x:Name="Normal">
                  <Storyboard>
                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.StrokeThickness)" Storyboard.TargetName="ellipse">
                      <EasingDoubleKeyFrame KeyTime="0:0:0.1" Value="0"/>
                    </DoubleAnimationUsingKeyFrames>
                  </Storyboard>
                </VisualState>
                <VisualState x:Name="MouseOver">
                  <Storyboard>
                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.StrokeThickness)" Storyboard.TargetName="ellipse">
                      <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="2"/>
                    </DoubleAnimationUsingKeyFrames>
                  </Storyboard>
                </VisualState>
                <VisualState x:Name="Pressed">
                  <Storyboard>
                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.StrokeThickness)" Storyboard.TargetName="ellipse">
                      <EasingDoubleKeyFrame KeyTime="0" Value="2"/>
                    </DoubleAnimationUsingKeyFrames>
                  </Storyboard>
                </VisualState>
                <VisualState x:Name="Disabled"/>
              </VisualStateGroup>
              <VisualStateGroup x:Name="CheckStates">
                <VisualState x:Name="Checked">
                  <Storyboard>
                    <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[0].(GradientStop.Color)" Storyboard.TargetName="ellipse">
                      <EasingColorKeyFrame KeyTime="0:0:0.3" Value="Red"/>
                    </ColorAnimationUsingKeyFrames>
                  </Storyboard>
                </VisualState>
                <VisualState x:Name="Unchecked">
                  <Storyboard>
                    <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[0].(GradientStop.Color)" Storyboard.TargetName="ellipse">
                      <EasingColorKeyFrame KeyTime="0:0:0.2" Value="#00FF0000"/>
                    </ColorAnimationUsingKeyFrames>
                  </Storyboard>
                </VisualState>
                <VisualState x:Name="Indeterminate"/>
              </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>
            <Ellipse x:Name="ellipse" Stroke="Yellow" StrokeThickness="0">
              <Ellipse.Fill>
                <RadialGradientBrush>
                  <GradientStop Color="Red"/>
                  <GradientStop Offset="1" Color="#00FF0000"/>
                </RadialGradientBrush>
              </Ellipse.Fill>
            </Ellipse>
          </Grid>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

您可以在Checked和Unchecked状态下看到对两个Storyboard的错误引用。但是我不同意错误,因为属性没有指向DependencyObject(无论是什么......),因为Target是“ellipse”,它就在那里;并且Target属性指向Shape的填充,就在那里(Ellipse的填充);到GreadientBrush的GradientStops [0],在RadialGradientBrush中有2个GradientStop;最后是GradientStop的Color属性,也就是那里。

有人有建议吗?

提前致谢。

1 个答案:

答案 0 :(得分:2)

有人帮我解决了一个问题(我不知道你是否会将其称为直接解决方案或解决方案):

如果您为GradientStop指定名称,则可以直接引用其Color属性:

<Ellipse.Fill>
  <RadialGradientBrush>
    <GradientStop x:Name="Offset0" Color="Red"/>
    <GradientStop x:Name="Offset1" Offset="1" Color="#00FF0000"/>
  </RadialGradientBrush>
</Ellipse.Fill>

[...]

<VisualState x:Name="Checked">
  <Storyboard>
    <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="Color" Storyboard.TargetName="Offset0">
      <EasingColorKeyFrame KeyTime="0:0:0.3" Value="Red"/>
    </ColorAnimationUsingKeyFrames>
  </Storyboard>
</VisualState>
<VisualState x:Name="Unchecked">
  <Storyboard>
    <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="Color" Storyboard.TargetName="Offset0">
      <EasingColorKeyFrame KeyTime="0:0:0.2" Value="#00FF0000"/>
    </ColorAnimationUsingKeyFrames>
  </Storyboard>
</VisualState>

我想这种方法不应该是必要的,但它看起来确实很优雅。

相关问题