2010-12-03 58 views
3

我正在使用Expression Blend 4 + Visual Studio 2010 Pro創建一個WPF應用程序。VS2010中的InvalidOperationException

我已經創建了一個基於CheckBox的控件Style(或者我應該說Template?),只使用Blend 4,它完美地工作。然而,當我去VS2010我得到了下面的 「錯誤」:。

'[未知]' 屬性不指向 爲DependencyObject路徑 「(0)(1)[0](2 )」。

即使當我運行該應用程序,它的工作原理非常好。現在,我不需要需要來解決這個錯誤,但我想擺脫它。

這裏是樣式的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> 

正如你可以看到在選中和未選中狀態既故事板的錯誤引用。然而我不同意這個錯誤,因爲這個屬性並沒有指向一個DependencyObject(不管那是...),因爲Target是「橢圓」的,目標物業指向一個形狀的填充,就在那裏(橢圓的填充);到GreadientBrush的GradientStops [0],在RadialGradientBrush中有2個GradientStops;最後到達GradientStop的Color屬性,該屬性也在那裏。

有沒有人有建議?

在此先感謝。

回答

2

有人幫我一個解決方案(我不知道你是否會說它是一個直接的解決方案或變通):如果你給一個名字漸變停止,你可以直接引用它的顏色屬性

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

我想這種方法不應該是必要的,但它確實看起來很優雅。

相關問題