Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1230
xamDataChart Legend Marker visibility
posted

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

  • 1230
    Verified Answer
    Offline posted

    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;
    }
    }

    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>