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 197961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:53:51+00:00 2026-05-11T16:53:51+00:00

I’m in the process of making a custom control — specifically a pie chart.

  • 0

I’m in the process of making a custom control — specifically a pie chart. I want the markup to look something like this example:

<c:PieChart>
    <!-- These dependency properties are never set -->
    <c:Slice Value="{Binding RedCount}" />
    <c:Slice Value="{Binding BlueCount}" />
    <c:Slice Value="{Binding GreenCount}" />
</c:PieChart>

PieChart derives from Control:

[ContentProperty("Slices")]
public class PieChart : Control
{
    public PieChart()
    {
        Slices = new ObservableCollection<Slice>();
    }

    public ObservableCollection<Slice> Slices { get; private set; }
}

The above XAML causes the Slices property to be populated with three instances of Slice.

Here’s a snippet from Slice:

public class Slice : ContentControl
{
    public static DependencyProperty ValueProperty
        = DependencyProperty.Register(
            "Value", typeof(double), typeof(Slice),
            new PropertyMetadata((p,a) => ((Slice)p).OnValueChanged(a)));

    private void OnValueChanged(DependencyPropertyChangedEventArgs e)
    {
        // This code never called!
    }
}

The problem is that the Value property on Slice is never set. If I put the dependency property on the PieChart and copy the binding expression, then the value is set, so I’m confident that I understand the basics of dependency properties and bindings.

So, what do I have to do to have my dependency property set a value on the child item? As these items are in my own collection, are they somehow not in the logical tree recognised by whatever magic makes bindings work?

A simple ‘do this’ answer would be helpful, but I’d really like to understand what’s going wrong here, so I’ll accept the most insightful, explanatory answer posted.

EDIT I didn’t make it clear but there is some ambient object on the DataContext of the PieChart that contains the properties RedCount, etc. In the past, when I’ve had a typo in a binding’s path (or some other mistake) I’ve seen warnings in the VS output window at runtime. In this case, I see nothing.

  • 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-11T16:53:52+00:00Added an answer on May 11, 2026 at 4:53 pm

    It looks like the Slice controls aren’t getting hooked up to the visual tree. They are just member variables, and WPF doesn’t know it’s meant to be displaying them as child elements of the PieChart. A couple of possible approaches:

    Have PieChart call AddLogicalChild to add the Slice objects. You will need to handle the possibility of Slices being added to or removed from the collection at runtime. This is pretty low level: MSDN advises, “For control authors, manipulating the logical tree at this level is not the recommended practice, unless none of the content models for available base control classes are appropriate for your control scenario. Consider subclassing at the level of ContentControl, ItemsControl, and HeaderedItemsControl.”

    Make PieChart a Panel. The Slices will then be its children, but note that the Children property is weakly typed, so people could add anything to a PieChart. This is not inherently a bad or a good thing; it’s a design consideration (see note below). But it’s probably not what you want in your case.

    Make PieChart an ItemsControl, and override GetContainerForItemOverride, IsItemItsOwnContainerOverride and possibly PrepareContainerForItemOverride to create/respect Slice controls. (Cf. ListBox and ListBoxItem, ComboBox and ComboBoxItem, etc.) A nice feature of this is that users can then use an ItemsSource and a DataTemplate (like a ListBox) instead of having to create the child controls by hand. (But users can still create fixed Slices in XAML per your syntax, just as they can create ListBoxItems in XAML.)

    You could even consider a hybrid approach, e.g. factoring out the radial layout functionality into a RadialLayoutPanel and the pie slice generation into an ItemsControl which uses a RadialLayoutPanel as its ItemsPanel.

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

Sidebar

Ask A Question

Stats

  • Questions 124k
  • Answers 124k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Your view function is also called login, and the call… May 12, 2026 at 1:14 am
  • Editorial Team
    Editorial Team added an answer For VB, Tools –> Options –> Text Editor –> Basic… May 12, 2026 at 1:14 am
  • Editorial Team
    Editorial Team added an answer This is probably due to the limitations of your DVI… May 12, 2026 at 1:14 am

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.