I am using the sample from Telerik Demo to create pie chart, and register to .LayoutUpdate event, at which doing following:
private void pieChart_LayoutUpdated(object sender, System.EventArgs e)
{
var paths = ChildrenOfTypeExtensions.ChildrenOfType<Path>(PieChart.Series[0]).ToList();
if (paths.Count == 0)
return;
PieChart.LayoutUpdated -= pieChart_LayoutUpdated;
foreach (var path in paths)
{
var dataPoint = path.Tag as PieDataPoint;
if (dataPoint == null)
return;
path.MouseEnter += uiElement_MouseEnter;
path.MouseLeave += uiElement_MouseLeave;
}
}
private void uiElement_MouseEnter(object sender, MouseEventArgs e)
{
var bar = (UIElement) sender;
bar.Opacity = 0.5;
}
private void uiElement_MouseLeave(object sender, MouseEventArgs e)
{
var bar = (UIElement)sender;
bar.Opacity = 1;
}
But I wanted more than just highlighting on pie "path", I want the associated label to be highlighted too.
Which at the moment, I am doing something like this:
<Style x:Key="SlicerNameTextBoxStyle" TargetType="TextBlock">
<Setter Property="Foreground" Value="{Binding DataItem, Converter={StaticResource SlicerToBrushConverter}}"></Setter>
<Setter Property="FontWeight" Value="{Binding DataItem, Converter={StaticResource SlicerToNameConverter}}"></Setter>
<Setter Property="FontFamily" Value="Segoe UI" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="{StaticResource MouseOverBrush}"></Setter>
</Trigger>
</Style.Triggers>
</Style>
<telerik:PieSeries.LabelDefinitions>
<telerik:ChartSeriesLabelDefinition Margin="-4,0,0,0"
DefaultVisualStyle="{StaticResource SlicerNameTextBoxStyle}">
<telerik:ChartSeriesLabelDefinition.Template>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding DataItem.DisplayName}"
HorizontalAlignment="Center"
Style="{StaticResource SlicerNameTextBoxStyle}"
MouseDown="SlicerPieLabel_OnMouseDown"/>
</StackPanel>
</DataTemplate>
</telerik:ChartSeriesLabelDefinition.Template>
</telerik:ChartSeriesLabelDefinition>
</telerik:PieSeries.LabelDefinitions>
As you can see, the problem is that I can't connect the pie slice and label highlight together, and I duplicated the pie selection changed event.
Can you help me to provide a better solution here?
Thanks,
Mingxue