Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4095816
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T19:57:08+00:00 2026-05-20T19:57:08+00:00

I have a ControlTemplate that contains a XamWebChart . For each pie slice created

  • 0

I have a ControlTemplate that contains a XamWebChart. For each pie slice created in my series, I would like its fill color bound to the same source the Value and Label are coming from.

The current xaml for my pie chart looks like:

<ControlTemplate x:Key="DataLocation">
 <Viewbox 
 Width="{TemplateBinding Width}" 
 Height="{TemplateBinding Height}"                
 Stretch="Fill">
 <Grid>
 <Grid.Resources>
 <Style x:Key="PieChartSeriesStyle" TargetType="Chart:Series">
  <Setter Property="Stroke" Value="#00FFFFFF" />                            
  <Setter Property="Marker">
    <Setter.Value>
     <Chart:Marker Foreground="#FFFFFFFF" />
    </Setter.Value>
  </Setter>
  </Style>
</Grid.Resources>
<Chart:XamWebChart x:Name="PieChart" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
  <Chart:XamWebChart.Scene>
   <Chart:Scene>
    <Chart:Scene.GridArea>
      <Chart:GridArea BorderThickness="0" Background="#00FFFFFF" />
    </Chart:Scene.GridArea>
    </Chart:Scene>
   </Chart:XamWebChart.Scene>

<Chart:XamWebChart.Series>
  <Chart:Series 
   ChartType="Pie" 
   Style="{StaticResource PieChartSeriesStyle}" 
   DataMapping="Value=Amount;Label=Identifier"                                
   DataSource="{Binding Path=ToolTip.Details}" 
    Fill="{Binding DetailItem.ColorProvider.BackgroundColor}">
  </Chart:Series>                                   
</Chart:XamWebChart.Series>                        
</Chart:XamWebChart>
</Grid>
</Viewbox>
</ControlTemplate>

The objects that are Bound to this ControlTemplate are:

public sealed class GeographyDataItem{
        public IEnumerable<GeographyDataDetailItem> Details
        {
            get { return _details; }
        }

}

With children:

public sealed class GeographyDataDetailItem
    {
        private readonly IColorProvider _colorProvider;

        public IColorProvider ColorProvider
        {
            get { return _colorProvider; }
        }

        public string Identifier { get;  private set; }
        public double Amount { get; private set; }

        public GeographyDataDetailItem(string identifier, double amount, IColorProvider colorProvider)
        {
            _colorProvider = colorProvider;
            Identifier = identifier;
            Amount = amount;
        }        
    }

Where IColorProvider is:

public interface IColorProvider
{
    Color ForegroundColor { get; }
    Color BackgroundColor { get; }
}

The ControlTemplate binding is set to bind to GeographyDataItem elements.

The only issue I am having is binding the ForegroundColor property of GeographyDataDetailItem . IColorProvider to the Fill property of the Pie Data Series. I am not sure how to go about this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T19:57:09+00:00Added an answer on May 20, 2026 at 7:57 pm

    I was unable to achieve what I wanted in XAML, but was able to support this use case in the control code-behind.

    My solution is:

    ...
    <Chart:XamWebChart.Series>
     <Chart:Series ChartType="Pie"
       Style="{StaticResource PieChartSeriesStyle}"
       DataMapping="Value=Amount;Label=Identifier"
       DataSource="{Binding Path=ToolTip.Details}" 
       Loaded="SeriesLoaded" /> 
    <!-- Loaded Event Added !-->
    ...
    

    And the Code beind:

      private void SeriesLoaded(object sender, RoutedEventArgs e)
        {
            var series = (Series) sender;
            ColorDataPointSeries(series);
        }
    
        /// <summary>
        /// Colors in <see cref="DataPoint"/> from the bound DataSource for the pie chart layer control.
        /// </summary>
        /// <param name="series"></param>
        private static void ColorDataPointSeries(Series series)
        {
            //If nothing is bound there is nothing to do.
            if (null == series.DataSource)
                return;
    
            var dataSource = ((IEnumerable<GeographyDataDetailItem>) series.DataSource).ToList();
            var dataPoints = series.DataPoints;
    
            //Note, I am depending on the control to have the exact number of dataPoints as dataSource elements here.
            for (var sourceIndex = 0; sourceIndex < dataSource.Count(); sourceIndex++)
            {
                //Iterate through each dataSoruce, looking for a color provider.
                //If one exists, change the Fill property of the control DataPoint.
                var colorProvider = dataSource[sourceIndex].ColorProvider;
                if (null != colorProvider)
                    dataPoints[sourceIndex].Fill = new SolidColorBrush(colorProvider.BackgroundColor);
            }
        }            
    

    So, now each time a XamWebChart is loaded for render, the Fill color is applied from the data source. Binding listening to property changes is not necessary as I do not expect the color to change following the render.

    It would be nice to know an alternative to have this in XAML, to reduce this code-behind; however, for the time being this solved my problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 3 datagrids that share the same data type. I'd like to configure
Have a flash player that pops out into a separate popup browser window. And
I know similar questions have been asked in relation to animating items within an
I have a ListView Control bound to a ListCollectionView in a ViewModel. I wanted
Have the following scenario. I have a few form, which essentially have a few
have anyone found a substitution for RJS in Ruby on Rails for play? P.S.
have different files with same name, in different directories. In these files there are
Have an Action delegate and trying to use the ternary operator inside of it
How can i move a progress bar value( i am simulating a car mph
EDIT: Original title: When I add a custom control based on a timer, my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.