2017-01-12 8 views
0

私はのResourceDictionaryでツールチップのための次の単純なControlTemplateを持っている:WPF ControlTemplate:StaticResourceを使用すると、実行時にXML解析例外が発生します。どうして?

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
       xmlns:s="clr-namespace:System;assembly=mscorlib" 
       xmlns:mwt="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero" 
       xmlns:local="clr-namespace:SIMOCRANECMSReporting.Resources.ControlTemplates"> 
<ControlTemplate x:Key="CTToolTipRoundCorners" TargetType="{x:Type ToolTip}"> 
    <mwt:SystemDropShadowChrome Color="Gray" CornerRadius="3" Name="Shdw" SnapsToDevicePixels="True"> 
     <Border Background="#FFF6F2F2" Opacity="1" CornerRadius="3" BorderThickness="1" BorderBrush="#FFD5D1D1"> 
      <Grid> 
       <ContentPresenter Margin="{TemplateBinding Padding}" DataContext="{TemplateBinding DataContext}" /> 
      </Grid> 
     </Border> 
    </mwt:SystemDropShadowChrome> 
    <ControlTemplate.Triggers> 
     <Trigger Property="ToolTipService.HasDropShadow"> 
      <Setter Property="mwt:SystemDropShadowChrome.Effect" TargetName="Shdw"> 
       <Setter.Value> 
        <DropShadowEffect ShadowDepth="5" Opacity="0.8"/> 
       </Setter.Value> 
      </Setter> 
      <Setter Property="FrameworkElement.Margin" TargetName="Shdw"> 
       <Setter.Value> 
        <Thickness>0,0,10,10</Thickness> 
       </Setter.Value> 
      </Setter> 
      <Setter Property="mwt:SystemDropShadowChrome.Color" TargetName="Shdw"> 
       <Setter.Value> 
        <Color>#00878787</Color> 
       </Setter.Value> 
      </Setter> 
      <Trigger.Value> 
       <s:Boolean>True</s:Boolean> 
      </Trigger.Value> 
     </Trigger> 
    </ControlTemplate.Triggers> 
</ControlTemplate> 

それはApp.xaml内の他のリソースにマージされています...

<Application x:Class="SIMOCRANECMSReporting.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> 
     <ResourceDictionary.MergedDictionaries> 
      <ResourceDictionary Source="/FirstFloor.ModernUI;component/Assets/ModernUI.xaml" /> 
      <ResourceDictionary Source="/FirstFloor.ModernUI;component/Assets/ModernUI.Light.xaml"/> 
      <ResourceDictionary Source="/Resources/RedTextBox.xaml"/> 
      <ResourceDictionary Source="/Resources/RedTextBox2.xaml"/> 
      <ResourceDictionary Source="/Resources/ControlTemplates/CTToolTipRoundCorners.xaml"/> 
     </ResourceDictionary.MergedDictionaries> 
    </ResourceDictionary> 

</Application.Resources> 

... TextBoxスタイルのstyle.triggerセクションで使用されます:

DynamicResourceを使用すると、完璧に動作している間...

<ToolTip Template="{StaticResource ResourceKey=CTToolTipRoundCorners}" ... /> 

<ToolTip Template="{DynamicResource ResourceKey=CTToolTipRoundCorners}" ... /> 

質問:StaticResourceにはない、なぜ誰も説明できますが、例外につながるテンプレートを参照するようにStaticResourceを使用し

<Style x:Key="RedTextBox2" TargetType="{x:Type TextBoxBase}" BasedOn="{x:Null}"> ... some more xaml ... <Style.Triggers> <Trigger Property="Validation.HasError" Value="True"> <Setter Property="ToolTip"> <Setter.Value> <ToolTip Template="{StaticResource ResourceKey=CTToolTipRoundCorners}" DataContext="{Binding RelativeSource={RelativeSource Self}, Path=PlacementTarget}" Padding="10" HasDropShadow="True"> <ItemsControl ItemsSource="{Binding Path=(Validation.Errors)}" DisplayMemberPath="ErrorContent"/> </ToolTip> </Setter.Value> </Setter> </Trigger> </Style.Triggers> </Style> 

作業?

答えて

0

リソースディクショナリのインクルード順が重要です。 CTToolTipRoundCornersを含む辞書は、あなたのApp.xamlを見てみるとRedTextBox2

を含む辞書の前に含まれていることを確認し、私はあなたが次のことを書くべき前提としています

<Application x:Class="SIMOCRANECMSReporting.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> 
     <ResourceDictionary.MergedDictionaries> 
      <ResourceDictionary Source="/FirstFloor.ModernUI;component/Assets/ModernUI.xaml" /> 
      <ResourceDictionary Source="/FirstFloor.ModernUI;component/Assets/ModernUI.Light.xaml"/> 
      <ResourceDictionary Source="/Resources/ControlTemplates/CTToolTipRoundCorners.xaml"/> 
      <ResourceDictionary Source="/Resources/RedTextBox.xaml"/> 
      <ResourceDictionary Source="/Resources/RedTextBox2.xaml"/>     
     </ResourceDictionary.MergedDictionaries> 
    </ResourceDictionary> 

</Application.Resources> 
+0

SnowballTwo、どうもありがとうございました。今はStaticResourceでも動作します。 –

関連する問題