Good day,
I have a xamChart which is populated with series programmatically. The user has the option to turn on markers containing data values, which is done through a DataTemplate as follows:
Background="WhiteSmoke" BorderBrush="{Binding Series.ActualMarkerOutline}" BorderThickness="1"> Text="{Binding Item.AxisYValueFormatted}" Foreground="Black" FontSize="12" HorizontalAlignment="Center" />
And assigned in C# using:
chartSeries.SetValue(Infragistics.Controls.Charts.MarkerSeries.MarkerTemplateProperty, this.FindResource("markerValueDataTemplate"));
I need to hide the empty marker balloons in the Legend representation of each series, as the visuals don't work very well. Is this possible?
Thanks in advance,
Reinhardt
Hello,
Thank you for your feedback. I am glad that you resolved your issue and I believe that other community members may benefit from this as well.
Thanks again.
Apologies for replying to my own post :)
The solution is to add a visibility converter to the DataTemplate which binds to the [Item] object. The [Item] object is null when the DataTemplate is rendered for the legend.
The Converter:
public class EmptyValueToVisibilityConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if ((value == DBNull.Value || value == null) == false && value.ToString().Trim().Length > 0) return Visibility.Visible; else return Visibility.Collapsed; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { return null; } }
public class EmptyValueToVisibilityConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if ((value == DBNull.Value || value == null) == false && value.ToString().Trim().Length > 0) return Visibility.Visible; else return Visibility.Collapsed; }
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { return null; } }
And the modified DataTemplate:
<DataTemplate x:Key="markerValueDataTemplate" x:Name="MarkerValueDataTemplate"> <Grid Height="20" Margin="0, -25, 0, 0" Visibility="{Binding Item, Converter={StaticResource emptyValueToVisibility}}"> <Border CornerRadius="5" Background="WhiteSmoke" BorderBrush="{Binding Series.ActualMarkerOutline}" BorderThickness="1"> <TextBlock Margin="2" Text="{Binding Item.AxisYValueFormatted}" Foreground="Black" FontSize="12" HorizontalAlignment="Center" /> </Border> </Grid> </DataTemplate>