我想在WPFToolkit圖表中設置派生數據點的樣式。基本上我想改變工具提示。它可以工作,但數據點的視覺狀態不會改變。在WPFToolkit中設計PieDataPoint時的視覺狀態問題圖
我已經從源代碼複製了樣式,並修改了工具提示僅用於添加FormattedIndependentValue
。樣式如下所示:
<!-- charting:PieDataPoint -->
<Style x:Key="PieDataPointStyle" TargetType="charting:PieDataPoint">
<Setter Property="Background" Value="Orange" />
<Setter Property="BorderBrush" Value="White" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="IsTabStop" Value="False" />
<Setter Property="RatioStringFormat" Value="{}{0:p2}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="charting:PieDataPoint">
<Grid x:Name="Root" Opacity="1">
<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>
<Path x:Name="Slice" Data="{TemplateBinding Geometry}"
Fill="{TemplateBinding Background}"
Stroke="{TemplateBinding BorderBrush}"
StrokeMiterLimit="1">
<ToolTipService.ToolTip>
<StackPanel>
<ContentControl Content="{TemplateBinding FormattedIndependentValue}" />
<ContentControl Content="{TemplateBinding FormattedDependentValue}" />
<ContentControl Content="{TemplateBinding FormattedRatio}" />
</StackPanel>
</ToolTipService.ToolTip>
</Path>
<Path x:Name="SelectionHighlight" Data="{TemplateBinding GeometrySelection}" Fill="Red" StrokeMiterLimit="1" IsHitTestVisible="False" Opacity="0" />
<Path x:Name="MouseOverHighlight" Data="{TemplateBinding GeometryHighlight}" Fill="White" StrokeMiterLimit="1" IsHitTestVisible="False" Opacity="0" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
然後,我使用它爲圖表定義調色板。
<datavis:ResourceDictionaryCollection x:Key="ChartPallete">
<!-- blue -->
<ResourceDictionary>
<Style x:Key="DataPointStyle" TargetType="charting:PieDataPoint" BasedOn="{StaticResource PieDataPointStyle}">
<Setter Property="Background" Value="#007d9d"/>
</Style>
</ResourceDictionary>
<!-- green -->
<ResourceDictionary>
<Style x:Key="DataPointStyle" TargetType="charting:PieDataPoint" BasedOn="{StaticResource PieDataPointStyle}">
<Setter Property="Background" Value="#8fcd3e"/>
</Style>
</ResourceDictionary>
<!-- more resource dictionaries to a total of 15 -->
<datavis:ResourceDictionaryCollection x:Key="ChartPalette">
這個調色板我設置爲PieSeries
。
var series = new PieSeries();
series.Palette = Resources["ChartPalette"] as ResourceDictionaryCollection;
從調色板中的顏色被正確用於該切片,工具提示正確地顯示,但是當我鼠標懸停或點擊數據點(切片)的視覺狀態不改變。沒有任何故事板被執行。
任何想法我做錯了什麼?
注(精明的讀者):除了提示我也改變了Grid
(在Root
元素)的不透明度爲1
,因爲自從可視狀態不更改設置故事板Opacity
1不執行和切片將完全不透明。
是的,我正在使用Toolkit 3.5。我將試用新版本。 –
確實,4.0版本確實有效。幸運的是,我正在使用.NET 4.5,所以沒問題。感謝您的幫助。 –