2011-04-26 63 views
0
我有我的stying将错误消息显示说有问题

:找不到与名称/密钥PerformanceBarChartBarTemplate资源[线路:454位置:35]无法找到资源风格误差

我的风格码是:

<Style x:Key="MainChartStyle" TargetType="toolkit:Chart"> 
    <Setter Property="BorderThickness" Value="0" /> 
    <Setter Property="TitleStyle" Value="{StaticResource ChartTitle}"/> 
    <Setter Property="Palette"> 
     <Setter.Value> 
      <datavis:ResourceDictionaryCollection> 
       <ResourceDictionary> 
        <Style TargetType="toolkit:BarDataPoint"> 
         <Setter Property="Background" 
         Value="#FF57007f" /> 
         <Setter Property="BorderBrush" 
         Value="#FF2e0007" /> 
         <Setter Property="Template" 
         Value="{StaticResource PerformanceBarChartBarTemplate}" /> 
        </Style> 
       </ResourceDictionary> 
      </datavis:ResourceDictionaryCollection> 
     </Setter.Value> 
    </Setter> 
    <Setter Property="LegendStyle"> 
     <Setter.Value> 
      <Style TargetType="dataVisualizationToolkit:Legend"> 
       <Setter Property="Margin" 
        Value="15,0,15,0" /> 
       <Setter Property="VerticalAlignment" 
        Value="Center" /> 
       <Setter Property="BorderBrush" 
        Value="Transparent" /> 
       <Setter Property="Background" 
        Value="Transparent" /> 
      </Style> 
     </Setter.Value> 
    </Setter> 
    <Setter Property="ChartAreaStyle"> 
     <Setter.Value> 
      <Style TargetType="Panel"> 
       <Setter Property="MinWidth" Value="100"/> 
       <Setter Property="MinHeight" Value="75"/> 
      </Style> 
     </Setter.Value> 
    </Setter> 
    <Setter Property="PlotAreaStyle"> 
     <Setter.Value> 
      <Style TargetType="Grid"> 
       <Setter Property="Background" 
        Value="Transparent"> 
       </Setter> 
      </Style> 
     </Setter.Value> 
    </Setter> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="toolkit:Chart"> 
       <Border Background="{TemplateBinding Background}" 
        BorderBrush="{TemplateBinding BorderBrush}" 
        BorderThickness="{TemplateBinding BorderThickness}" 
        Padding="10"> 
        <Grid> 
         <Grid.RowDefinitions> 
          <RowDefinition Height="Auto"/> 
          <RowDefinition Height="*"/> 
         </Grid.RowDefinitions> 
         <dataVisualizationToolkit:Title Style="{TemplateBinding TitleStyle}" 
               Content="{TemplateBinding Title}" /> 
         <Grid Margin="0,15,0,15" 
          Grid.Row="1"> 
          <Grid.ColumnDefinitions> 
           <ColumnDefinition Width="*" /> 
           <ColumnDefinition Width="Auto" /> 
          </Grid.ColumnDefinitions> 
          <dataVisualizationToolkit:Legend x:Name="Legend" 
              Style="{TemplateBinding LegendStyle}" 
              Grid.Column="1"/> 
          <toolkitChartingPrimitives:EdgePanel x:Name="ChartArea" 
              Style="{TemplateBinding ChartAreaStyle}"> 
           <Grid Style="{TemplateBinding PlotAreaStyle}" 
            Canvas.ZIndex="-1" /> 
          </toolkitChartingPrimitives:EdgePanel> 
         </Grid> 
        </Grid> 
       </Border> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 

而且它不能看到控制:

<ControlTemplate x:Key="PerformanceBarChartBarTemplate" 
      TargetType="toolkit:BarDataPoint"> 
    <Border BorderThickness="0" 
     Opacity="0" 
     x:Name="Root"> 
     <VisualStateManager.VisualStateGroups> 
      <VisualStateGroup x:Name="CommonStates"> 
       <VisualStateGroup.Transitions> 
        <VisualTransition GeneratedDuration="0:0:0.1" /> 
       </VisualStateGroup.Transitions> 
       <VisualState x:Name="Normal" /> 
       <VisualState x:Name="MouseOver"> 
        <Storyboard> 
         <DoubleAnimation Storyboard.TargetName="MouseOverHighlight" 
            Storyboard.TargetProperty="Opacity" 
            To="0.6" 
            Duration="0" /> 
        </Storyboard> 
       </VisualState> 
      </VisualStateGroup> 
      <VisualStateGroup x:Name="SelectionStates"> 
       <VisualStateGroup.Transitions> 
        <VisualTransition GeneratedDuration="0:0:0.1" /> 
       </VisualStateGroup.Transitions> 
       <VisualState x:Name="Unselected" /> 
       <VisualState x:Name="Selected"> 
        <Storyboard> 
         <DoubleAnimation Storyboard.TargetName="SelectionHighlight" 
            Storyboard.TargetProperty="Opacity" 
            To="0.6" 
            Duration="0" /> 
        </Storyboard> 
       </VisualState> 
      </VisualStateGroup> 
      <VisualStateGroup x:Name="RevealStates"> 
       <VisualStateGroup.Transitions> 
        <VisualTransition GeneratedDuration="0:0:0.5" /> 
       </VisualStateGroup.Transitions> 
       <VisualState x:Name="Shown"> 
        <Storyboard> 
         <DoubleAnimation Storyboard.TargetName="Root" 
            Storyboard.TargetProperty="Opacity" 
            To="1" 
            Duration="0" /> 
        </Storyboard> 
       </VisualState> 
       <VisualState x:Name="Hidden"> 
        <Storyboard> 
         <DoubleAnimation Storyboard.TargetName="Root" 
            Storyboard.TargetProperty="Opacity" 
            To="0" 
            Duration="0" /> 
        </Storyboard> 
       </VisualState> 
      </VisualStateGroup> 
     </VisualStateManager.VisualStateGroups> 

     <Grid Margin="0 4 0 4"> 
      <Grid.RowDefinitions> 
       <RowDefinition Height="*" /> 
       <RowDefinition Height="*" /> 
      </Grid.RowDefinitions> 

      <!-- Main bar shape --> 
      <Rectangle Fill="{TemplateBinding Background}" 
        Stroke="{TemplateBinding BorderBrush}" 
        StrokeThickness="{TemplateBinding BorderThickness}" 
        RadiusX="3" 
        RadiusY="3" 
        Grid.Row="0" 
        Grid.RowSpan="2"> 
       <Rectangle.Effect> 
        <DropShadowEffect BlurRadius="10" 
            Direction="0" 
            Color="#FFFFFFFF" 
            ShadowDepth="0" /> 
       </Rectangle.Effect> 
      </Rectangle> 


      <!-- Diffuse Glow --> 
      <Rectangle RadiusX="3" 
        RadiusY="3" 
        Margin="4" 
        Grid.Row="0" 
        Grid.RowSpan="2" 
        Opacity=".25" 
        Fill="White" 
        > 
       <Rectangle.Effect> 
        <BlurEffect Radius="8" /> 
       </Rectangle.Effect> 

      </Rectangle> 


      <!-- Specular Highlight --> 
      <Rectangle RadiusX="3" 
        RadiusY="3" 
        Margin="2" 
        Grid.Row="0"> 

       <Rectangle.Fill> 
        <LinearGradientBrush> 
         <GradientStop Color="#99ffffff" 
            Offset="0" /> 
         <GradientStop Color="#22ffffff" 
            Offset="1" /> 
        </LinearGradientBrush> 
       </Rectangle.Fill> 
      </Rectangle> 

      <!--<Border BorderBrush="#ccffffff" 
       BorderThickness="1"> 
      <Border BorderBrush="#77ffffff" 
        BorderThickness="1" /> 
     </Border>--> 

      <Rectangle x:Name="SelectionHighlight" 
        Fill="Red" 
        Opacity="0" /> 
      <Rectangle x:Name="MouseOverHighlight" 
        RadiusX="3" 
        RadiusY="3" 
        Fill="White" 
        Opacity="0" /> 
     </Grid> 
     <ToolTipService.ToolTip> 
      <ContentControl Content="{TemplateBinding FormattedDependentValue}" /> 
     </ToolTipService.ToolTip> 
    </Border> 
</ControlTemplate> 

回答

2

我想你只需要移动“PerformanceBarChartBarT emplate'控件模板,超出您在资源部分中定义的样式。

编辑: 首先,你需要包装的风格模板,并给它一个名称

<Style x:Key="BarDataPointStyle" TargetType="toolkit:DataPoint"> 
    <Setter Property="Template" Value="{StaticResource PerformanceBarChartBarTemplate}"/> 
</Style> 

这样做的原因是因为我发现我已经有一个名为“内部风格DataPointStyle '让它工作,然后我使用BasedOn来获取您的模板。 这里是你如何定义调色板。

我希望这有助于。

解决方案2: 只需用您的调色板替换您的调色板。你会注意到我在样式中添加了一个x:Key,这就是你所缺少的。我测试了它,它工作。

<Setter Property="Palette"> 
     <Setter.Value> 
      <toolkit:ResourceDictionaryCollection> 
       <ResourceDictionary> 
        <Style x:Key="DataPointStyle" TargetType="toolkit:BarDataPoint"> 
         <Setter Property="Background" 
           Value="#FF57007f" /> 
         <Setter Property="BorderBrush" 
           Value="#FF2e0007" /> 
         <Setter Property="Template" 
           Value="{StaticResource PerformanceBarChartBarTemplate}" /> 
        </Style> 
       </ResourceDictionary> 

       <ResourceDictionary> 
        <Style x:Key="DataPointStyle" TargetType="toolkit:BarDataPoint"> 
         <Setter Property="Background" 
           Value="Red" /> 
         <Setter Property="BorderBrush" 
           Value="Black" /> 
         <Setter Property="Template" 
           Value="{StaticResource PerformanceBarChartBarTemplate}" /> 
        </Style> 
       </ResourceDictionary> 
      </toolkit:ResourceDictionaryCollection> 
     </Setter.Value> 
    </Setter> 
+0

谢谢你解决这个问题 - 它仍然没有采取控制模板内的变化 - 任何想法? – Bruie 2011-04-26 13:43:54

+0

你的意思是什么改变? – 2011-04-26 13:49:52

+0

那么控制模板将改变工具提示,但是图表仍然显示默认工具提示 – Bruie 2011-04-26 14:01:26