Jump to content
Software FX Community

Conditional custom background within DataView


Recommended Posts


I would like to change the background color of several DataView cells, depending on values from two different series.

I tried to create a new serie, wich contains the values of the two others, and reference it in my DataView (with his index). But I dont find how to get the right DataItem.

Here is my snippet:

=> where i reference the new serie in the Chart's SeriesAttributesCollection

ItemsSource="{Binding ValuesAndInfluence}"

Visibility="Collapsed" BindingPathX="Datetime" BindingPath="Value"


=> in the DataView

Text="{Binding Path=????}"

VerticalAlignment="Center" HorizontalAlignment="Right" Padding="5 2 5 2" />

If I could get the right dataItem, I would finish with a converter for the backgroundcolor...

Thanks for your help!

Link to comment
Share on other sites

I think the snippet got lost in your posting but this is a sample of how to change the background color of your dataview cells, the key of the sample is that in most logical items we generate (and you can style to change the appearance of the bars, legend items, etc.) the DataItem property will typically point to the data you provided to the chart.

Data Model

public class BusinessData

  public double Y1 { get; set; }

  public double Y2 { get; set; }


XAML to customize chart, note that we use SeriesField, because of this you will automatically get some nice behaviors, for example if your axis was formatted as currency the ValueText property would reflect that, you could also have used DataField which can be used to place a field from your data even if it is not plotted as a series. Obviously you might want to place the template separately but this helps on sample simplicity.










  <local:BusinessDataColorConverter x:Key="businessDataColorConverter"/>


  <TextBlock Text="{Binding Path=ValueText}"
Background="{Binding Path=DataItem,
businessDataColorConverter}}" Margin="{Binding Path=Margin}"
Foreground="{Binding Path=Foreground}"
FontFamily="{Binding Path=FontFamily}"
FontWeight="{Binding Path=FontWeight}"
FontSize="{Binding Path=FontSize}"
FontStyle="{Binding Path=FontStyle}" HorizontalAlignment="Right"


Binding="{Binding Path=Dimmed}">




Property="Opacity" Value="0.25"












Code to populate chart

List<BusinessData> list = new

BusinessData() { Y1 = 10, Y2 = 12 });

BusinessData() { Y1 = 14, Y2 = 11 });

BusinessData() { Y1 = 11, Y2 = 17 });


chart1.Series.Add(new SeriesAttributes("Y1"));

chart1.Series.Add(new SeriesAttributes("Y2"));

chart1.ItemsSource = list;

Color Converter

object IValueConverter.Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture

  BusinessData businessData = (BusinessData) value;
if (businessData.Y1 > businessData.Y2)

return Brushes.Yellow;


return Brushes.White;




Link to comment
Share on other sites

Oups, you're right the snippet disappeared... :/

I tried your solution, it's perfect!

In fact, my series were independent each from the others (not in the same objet and binded to SeriesAttribute with ItemSource), so I added an objet like your BusinessData wich contains all of the collections.

Thanks for your help!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...