トップ回答者
Blendでタブコントロールのタブ背景を変更すると、VS2010でXAMLが解釈できない件

質問
-
いつもお世話になっております。
WPFアプリケーション作成中にExpression Blend4を使うとVS2010でXAML解析エラーになる件について質問したいと思います。
【手順】
①VS2010でWPFアプリケーションプロジェクト生成
②タブコントロールを1個配置し、タブアイテムを3個作成
③同じソリューションをExpressionBlend4でOpen
④どれかのタブアイテム上で右クリックし、「テンプレートの編集」⇒「コピーして編集」を選択
⑤状態タブの「SelectionStates」の「Selected」をクリック(記録状態になります)
⑥オブジェクトとタイムラインのClassicBorderを選択し、プロパティのBackGroundを変更
但し、デフォルトでBackgroud変更できないので一回「値のリセット」を行った後に、変更
⑦Blend上で実行すると正常に動作しているように見えるが、同じソリューションをVS2010で開くとXAMLでエラーが報告される。但し実行はできる。XAML解析エラーなのでVS2010上でデザインの編集は不可。
Backgroundのリセットをして値を変更したのが気にはなりますが、何か手順でおかしい所ありますでしょうか?
【Blendで生成されたXAML】
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Classic" x:Class="WpfApplication1.MainWindow" Title="MainWindow" Height="350" Width="525"> <Window.Resources> <Style x:Key="TabItemFocusVisual"> <Setter Property="Control.Template"> <Setter.Value> <ControlTemplate> <Rectangle Margin="4,4,4,2" SnapsToDevicePixels="true" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2"/> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style x:Key="TabItemStyle1" TargetType="{x:Type TabItem}"> <Setter Property="FocusVisualStyle" Value="{StaticResource TabItemFocusVisual}"/> <Setter Property="Padding" Value="12,2,12,2"/> <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/> <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/> <Setter Property="HorizontalContentAlignment" Value="Stretch"/> <Setter Property="VerticalContentAlignment" Value="Stretch"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type TabItem}"> <Microsoft_Windows_Themes:ClassicBorderDecorator x:Name="ClassicBorder" BorderBrush="{x:Static Microsoft_Windows_Themes:ClassicBorderDecorator.ClassicBorderBrush}" BorderThickness="2" BorderStyle="TabTop" SnapsToDevicePixels="true" Background="Black"> <VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="SelectionStates"> <VisualState x:Name="Unselected"/> <VisualState x:Name="Selected"> <Storyboard> <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Panel.Background).(SolidColorBrush.Color)" Storyboard.TargetName="ClassicBorder"> <EasingColorKeyFrame KeyTime="0" Value="#FFDA1818"/> </ColorAnimationUsingKeyFrames> </Storyboard> </VisualState> </VisualStateGroup> </VisualStateManager.VisualStateGroups> <ContentPresenter ContentSource="Header" HorizontalAlignment="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/> </Microsoft_Windows_Themes:ClassicBorderDecorator> <ControlTemplate.Triggers> <Trigger Property="IsSelected" Value="true"> <Setter Property="Panel.ZIndex" Value="1"/> </Trigger> <Trigger Property="TabStripPlacement" Value="Bottom"> <Setter Property="BorderStyle" TargetName="ClassicBorder" Value="TabBottom"/> </Trigger> <Trigger Property="TabStripPlacement" Value="Left"> <Setter Property="BorderStyle" TargetName="ClassicBorder" Value="TabLeft"/> </Trigger> <Trigger Property="TabStripPlacement" Value="Right"> <Setter Property="BorderStyle" TargetName="ClassicBorder" Value="TabRight"/> </Trigger> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="IsSelected" Value="true"/> <Condition Property="TabStripPlacement" Value="Top"/> </MultiTrigger.Conditions> <Setter Property="Margin" Value="-2"/> </MultiTrigger> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="IsSelected" Value="true"/> <Condition Property="TabStripPlacement" Value="Bottom"/> </MultiTrigger.Conditions> <Setter Property="Margin" Value="-2"/> </MultiTrigger> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="IsSelected" Value="true"/> <Condition Property="TabStripPlacement" Value="Left"/> </MultiTrigger.Conditions> <Setter Property="Padding" Value="11,2,14,2"/> <Setter Property="Margin" Value="-2"/> </MultiTrigger> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="IsSelected" Value="true"/> <Condition Property="TabStripPlacement" Value="Right"/> </MultiTrigger.Conditions> <Setter Property="Padding" Value="14,2,11,2"/> <Setter Property="Margin" Value="-2"/> </MultiTrigger> <Trigger Property="IsEnabled" Value="false"> <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </Window.Resources> <Grid> <TabControl Height="278" HorizontalAlignment="Left" Margin="22,20,0,0" x:Name="tabControl1" VerticalAlignment="Top" Width="462"> <TabItem Header="tabItem1" x:Name="tabItem1" Style="{DynamicResource TabItemStyle1}" > <Grid /> </TabItem> <TabItem Header="tabItem2" x:Name="tabItem2"> <Grid /> </TabItem> <TabItem Header="tabItem3" x:Name="tabItem3"> <Grid /> </TabItem> </TabControl> </Grid> </Window>
【エラー内容】
'System.Windows.Media.Animation.ColorAnimationUsingKeyFrames' アニメーション オブジェクトは、互換性のない型 'System.Windows.Media.Brush' であるため、プロパティ 'Background' をアニメーションで表示するためには使用できません。 場所 System.Windows.Media.Animation.Storyboard.VerifyAnimationIsValid(DependencyProperty targetProperty, AnimationClock animationClock) 場所 System.Windows.Media.Animation.Storyboard.ProcessComplexPath(HybridDictionary clockMappings, DependencyObject targetObject, PropertyPath path, AnimationClock animationClock, HandoffBehavior handoffBehavior, Int64 layer) 場所 System.Windows.Media.Animation.Storyboard.ClockTreeWalkRecursive(Clock currentClock, DependencyObject containingObject, INameScope nameScope, DependencyObject parentObject, String parentObjectName, PropertyPath parentPropertyPath, HandoffBehavior handoffBehavior, HybridDictionary clockMappings, Int64 layer) 場所 System.Windows.Media.Animation.Storyboard.ClockTreeWalkRecursive(Clock currentClock, DependencyObject containingObject, INameScope nameScope, DependencyObject parentObject, String parentObjectName, PropertyPath parentPropertyPath, HandoffBehavior handoffBehavior, HybridDictionary clockMappings, Int64 layer) 場所 System.Windows.Media.Animation.Storyboard.BeginCommon(DependencyObject containingObject, INameScope nameScope, HandoffBehavior handoffBehavior, Boolean isControllable, Int64 layer) 場所 System.Windows.VisualStateGroup.StartNewThenStopOld(FrameworkElement element, Storyboard[] newStoryboards) 場所 System.Windows.VisualStateManager.GoToStateInternal(FrameworkElement control, FrameworkElement stateGroupsRoot, VisualStateGroup group, VisualState state, Boolean useTransitions) 場所 System.Windows.VisualStateManager.GoToStateCommon(FrameworkElement control, FrameworkElement stateGroupsRoot, String stateName, Boolean useTransitions) 場所 System.Windows.VisualStateManager.GoToState(FrameworkElement control, String stateName, Boolean useTransitions) 場所 System.Windows.Controls.VisualStates.GoToState(Control control, Boolean useTransitions, String[] stateNames) 場所 System.Windows.Controls.TabItem.ChangeVisualState(Boolean useTransitions) 場所 System.Windows.Controls.Control.UpdateVisualState(Boolean useTransitions) 場所 System.Windows.Controls.Control.OnPostApplyTemplate() 場所 System.Windows.FrameworkElement.ApplyTemplate() 場所 Microsoft.Expression.Platform.WPF.WpfViewNodeManager.EnsureElementInDictionary(Object root, ViewNode knownAncestor)
回答
すべての返信
-
なるほど・・・Windows XP SP3・・・たぶんクラシックモードですよね。
Windows 7 でも クラシックモードにしたら、ClassicBorderDecorator が生成されました。
で、こちらの環境(Win7 & クラシックモードに変更)で質問の手順通り試したら、確かに実行はできますが、Visual Studio のデザインではSystem.Reflection.TargetInvocationException
System.Windows.Media.Animation.ColorAnimationUsingKeyFrames' アニメーション オブジェクトは、互換性のない型 'System.Windows.Media.Brush' であるため、プロパティ 'Background' をアニメーションで表示するためには使用できません。が発生しました。
ただしクラシックモードでなく、Aero スタイルで Border を編集すれば大丈夫みたいです。
ひらぽん http://d.hatena.ne.jp/hilapon/
- 編集済み ひらぽんModerator 2011年10月31日 3:50
-
ごめんなさい。Aero でも
> 但し、デフォルトでBackgroud変更できないので一回「値のリセット」を行った後に、変更
Border に対してこれやったらダメでした。詳細は不明です。
ひらぽん http://d.hatena.ne.jp/hilapon/- 編集済み ひらぽんModerator 2011年10月31日 3:59
-
⑦Blend上で実行すると正常に動作しているように見えるが、同じソリューションをVS2010で開くとXAMLでエラーが報告される。但し実行はできる。XAML解析エラーなのでVS2010上でデザインの編集は不可。
残念ながらVS2010では解析できないXAMLが存在します。実行できるのであればXAMLは問題なく、VS2010のXAMLデザイナーがまだそのようなレベルであると認識するしかありません。
(参考)
添付プロパティに配列を渡す際のVisual Studio 2010 WPFデザイナーのバグ?
http://d.hatena.ne.jp/trapemiya/20100716/1279244773CallMethodActionを継承したBehaviorを指定するとVisual Studio 2010のXAMLデザイナで例外が発生する
http://d.hatena.ne.jp/trapemiya/20101001/1285898582現在Connectでは残念ながら日本語で不具合をフィードバックすることができないようですが、いずれ復活するかもしれません。
また、VS2010はSP1を適用されていないようですが、状況が許せば適用されてみてはいかがでしょうか? ひょっとするとはですが、直るかもしれません。
★良い回答には回答済みマークを付けよう! わんくま同盟 MVP - Visual C# http://d.hatena.ne.jp/trapemiya/ -
同じような現象かもしれませんが、実は以下のような問題もあるのですが、
これも実行すると問題なく実行できるので、VS2010のXAMLデザイナーのバグなんですかね?
trapemiyaさんのリンクにあるようなことでしょうか?エラー内容は少し違うような気もするのですが。。。
【手順】
①VS2010にて、WPFアプリケーション作成
②ボタンを1個追加
③App.xamlに以下のようなボタンの定義をBlendにより、作成し、ボタンに適用。
④MainWindow.xamlにて
「"btnSetting"でInvalidOperationExceptionがスローされました:'[Unknown]'プロパティはパス'(0).(1)[0].(2)'でDependencyObjectをポイントしません。」
と表示。詳細は以下。
うーん。解析エラーはともかくエラーメッセージって消せないのでしょうか・・・XAMLデザイナーの上に覆いかぶさっているので、
どうしようもない。。。
【MainWindow.xaml】
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Classic" x:Class="WpfApplication1.MainWindow" Title="MainWindow" Height="350" Width="525"> <Grid> <Button Content="設定" Margin="0,0,195.381,0" x:Name="btnSetting" VerticalAlignment="Center" FontSize="24" HorizontalAlignment="Right" Foreground="Black" BorderBrush="White" BorderThickness="2" Width="150" Height="50" Style="{DynamicResource Buttongray}" > </Button> </Grid> </Window>
【App.xaml】
【解析エラー内容】<Application x:Class="WpfApplication1.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml"> <Application.Resources> <ResourceDictionary> <Style x:Key="Buttongray" TargetType="{x:Type Button}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Grid> <VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="CommonStates"> <VisualState x:Name="Normal"> <Storyboard> <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[0].(GradientStop.Offset)" Storyboard.TargetName="rectangle"> <EasingDoubleKeyFrame KeyTime="0" Value="0.991"/> </DoubleAnimationUsingKeyFrames> <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[0].(GradientStop.Color)" Storyboard.TargetName="rectangle"> <EasingColorKeyFrame KeyTime="0" Value="#FFB4B4B4"/> </ColorAnimationUsingKeyFrames> <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[1].(GradientStop.Color)" Storyboard.TargetName="rectangle"> <EasingColorKeyFrame KeyTime="0" Value="Gainsboro"/> </ColorAnimationUsingKeyFrames> </Storyboard> </VisualState> <VisualState x:Name="MouseOver"> <Storyboard> <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[0].(GradientStop.Color)" Storyboard.TargetName="rectangle"> <EasingColorKeyFrame KeyTime="0" Value="#FFD2D2D2"/> </ColorAnimationUsingKeyFrames> <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[1].(GradientStop.Color)" Storyboard.TargetName="rectangle"> <EasingColorKeyFrame KeyTime="0" Value="#FFFAFAFA"/> </ColorAnimationUsingKeyFrames> </Storyboard> </VisualState> <VisualState x:Name="Pressed"> <Storyboard> <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[0].(GradientStop.Offset)" Storyboard.TargetName="rectangle"> <EasingDoubleKeyFrame KeyTime="0" Value="0.996"/> </DoubleAnimationUsingKeyFrames> <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[0].(GradientStop.Color)" Storyboard.TargetName="rectangle"> <EasingColorKeyFrame KeyTime="0" Value="#FF8C8C8C"/> </ColorAnimationUsingKeyFrames> <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[1].(GradientStop.Color)" Storyboard.TargetName="rectangle"> <EasingColorKeyFrame KeyTime="0" Value="#FFB4B4B4"/> </ColorAnimationUsingKeyFrames> </Storyboard> </VisualState> <VisualState x:Name="Disabled"/> </VisualStateGroup> </VisualStateManager.VisualStateGroups> <Rectangle x:Name="rectangle" RadiusY="5" RadiusX="5" Stroke="White" StrokeThickness="2"> <Rectangle.Effect> <DropShadowEffect ShadowDepth="0" Color="#FF646464"/> </Rectangle.Effect> <Rectangle.Fill> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="#FFC8C8C8" Offset="1"/> <GradientStop Color="#FFF0F0F0"/> </LinearGradientBrush> </Rectangle.Fill> </Rectangle> <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsFocused" Value="True"/> <Trigger Property="IsDefaulted" Value="True"/> <Trigger Property="IsMouseOver" Value="True"/> <Trigger Property="IsPressed" Value="True"/> <Trigger Property="IsEnabled" Value="False"/> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </ResourceDictionary> </Application.Resources> </Application>
場所 System.Windows.Media.Animation.Storyboard.VerifyPathIsAnimatable(PropertyPath path) 場所 System.Windows.Media.Animation.Storyboard.ClockTreeWalkRecursive(Clock currentClock, DependencyObject containingObject, INameScope nameScope, DependencyObject parentObject, String parentObjectName, PropertyPath parentPropertyPath, HandoffBehavior handoffBehavior, HybridDictionary clockMappings, Int64 layer) 場所 System.Windows.Media.Animation.Storyboard.ClockTreeWalkRecursive(Clock currentClock, DependencyObject containingObject, INameScope nameScope, DependencyObject parentObject, String parentObjectName, PropertyPath parentPropertyPath, HandoffBehavior handoffBehavior, HybridDictionary clockMappings, Int64 layer) 場所 System.Windows.Media.Animation.Storyboard.BeginCommon(DependencyObject containingObject, INameScope nameScope, HandoffBehavior handoffBehavior, Boolean isControllable, Int64 layer) 場所 System.Windows.VisualStateGroup.StartNewThenStopOld(FrameworkElement element, Storyboard[] newStoryboards) 場所 System.Windows.VisualStateManager.GoToStateInternal(FrameworkElement control, FrameworkElement stateGroupsRoot, VisualStateGroup group, VisualState state, Boolean useTransitions) 場所 System.Windows.VisualStateManager.GoToStateCommon(FrameworkElement control, FrameworkElement stateGroupsRoot, String stateName, Boolean useTransitions) 場所 System.Windows.VisualStateManager.GoToState(FrameworkElement control, String stateName, Boolean useTransitions) 場所 System.Windows.Controls.Primitives.ButtonBase.ChangeVisualState(Boolean useTransitions) 場所 System.Windows.Controls.Control.UpdateVisualState(Boolean useTransitions) 場所 System.Windows.Controls.Control.OnPostApplyTemplate() 場所 System.Windows.FrameworkElement.ApplyTemplate() 場所 Microsoft.Expression.Platform.WPF.WpfViewNodeManager.EnsureElementInDictionary(Object root, ViewNode knownAncestor)
-
同じような現象かもしれませんが、実は以下のような問題もあるのですが、
これも実行すると問題なく実行できるので、VS2010のXAMLデザイナーのバグなんですかね?
trapemiyaさんのリンクにあるようなことでしょうか?エラー内容は少し違うような気もするのですが。。。
【手順】
①VS2010にて、WPFアプリケーション作成
②ボタンを1個追加
③App.xamlに以下のようなボタンの定義をBlendにより、作成し、ボタンに適用。
④MainWindow.xamlにて
「"btnSetting"でInvalidOperationExceptionがスローされました:'[Unknown]'プロパティはパス'(0).(1)[0].(2)'でDependencyObjectをポイントしません。」
<VisualState x:Name="Normal">
が<Rectangle x:Name="rectangle" >
のプロパティを捜しに行ったところ、見つかれませんでした。
ldiary.com
- 編集済み Ldiary 2011年10月31日 23:18
-