Hello,
What is the best approach for assigning specific colors to specific XamPieChart slices? For example, the "On Time" slice should always be green, and the "Late" slice should always be red. If I simply declare a BrushCollection in XAML, then this works only if all possible data points are present, but if the "On Time" slice is empty, then the "Late" slice becomes green - wrong!. I have to avoid this scenario...each slice should have one and only one color it can use.
Thanks for your help!
Hi Francis,
I looked into this a bit and unfortunately there is no easy way to do this. The source code is specifically setting the background of the pie slice every time it sets the appearence. This will override any bindings or styles that are set. The only way I could get this to work was to handle the slice's LayoutUpdated event and everytime the layout updates I rebind the Slice to the data's Color property. It's a very hacky way to do this but it's the only way I found that works given the current limitations.
I've determined this to be a new feature request and have sent your product idea directly to our product management team. Our product team chooses new product ideas for development based on popular feedback from our customer base. Infragistics continues to monitor application development for all of our products, so as trends appear in requested features, we can plan accordingly.
We value your input, and our philosophy is to enhance our toolset based on customer feedback. If your feature is chosen for development, you will be notified at that time. Your reference number for this product idea is PI13050002.
If you would like to follow up on your product idea at a later point, you may contact Developer Support management via email. Please include the reference number of your product idea in the subject and body of your email message. You can reach Developer Support management through the following email address: dsmanager@infragistics.com
Hi Rob,
Thanks for your investigation and submitting the PI request.
As for the workaround idea, which I'd like to implement, whether hackish or not... If I handle LayoutUpdated in either your sample or in my application (using IG 12.2.20122.2053), sender is always null and e contains nothing. Can you please confirm that I can use this event handler for this purpose? Do you have any sample code doing the same?
Thanks again, Francis
PS - same behavior with 12.2.2012.2147
LayoutUpdated will not return the sender whether it's our controls or Microsoft's controls. The last forum post on this thread describes it best: http://social.msdn.microsoft.com/Forums/en-US/silverlightcontrols/thread/10beaf7a-df0f-405b-a72a-3701c4760c83/
I used LayoutUpdated because it fires very frequently. And because I used LayoutUpdated I needed to store the Slices once they were generated so I have access to them when the event fires. That's why you see a for loop in my sample code:
foreach (Slice slice in Slices) { Binding b = new Binding("Color"); slice.SetBinding(Slice.BackgroundProperty, b); }
I'm storing all the generated slices in a List<T> and iterating over all of them. Like I said it's a very hackish way to do this but given the limitations it was the only workaround I could come up with that worked.
OK, thanks for the update. I think I'm following, but the sample you sent may be the wrong one. No loops are in the sample at all. Did I get the right file from you?
Still trying to figure out how to get the collection of Slices. The XamPieChart doesn't expose them, as far as I can tell. Sorry to be a nag, but I reeaaaaallllllly need to see a functioning sample. :)
I've uploaded a modified version of my previous sample. If you open MainPage.xaml.cs and scroll to the bottom you will see a class called PieChartAttachedProperties where I'm storing the slices and using them in LayoutUpdated. When you run the new sample there will be a button at the bottom of the page. Click on that and you will see one of the pie slices change to black. The slice changes as a result of binding updates from within the underlying data.
If you look in MainPage.xaml, inside the XamPieChart resources you will see a style.
<Style TargetType="ig:Slice"> <Setter Property="Background" Value="{Binding Path=Color}"/> <Setter Property="local:PieChartAttachedProperties.BindSliceBackground" Value="True"/> </Style>
It sets the attached property to the Slice so when a Slice is generated the PieChartAttachedProperties class will store the slice to update the background accordingly.
Awesome, thanks! Your're right, it's a bit hacky, but works in my application. I doubt I would have figured this one out on my own.