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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:10:31+00:00 2026-05-25T11:10:31+00:00

I’ve made a custom control to display a pie chart representing the completion of

  • 0

I’ve made a custom control to display a pie chart representing the completion of a task. I’ve created a property in this custom to send out the percentage of completion of the task. Tested standalone: it works.
I want to use that control in a datagrid bound to a database, so i did a DataGridTemplateColumn to put my custom control in it.

PROBLEM: i can’t find a way to bind the field of my database to the property of the completion value.

Code for the control

public class PieChartControl : Control
{
    public static readonly DependencyProperty CompletionValueProperty;
    public double CompletionValue
    {
        get { return (double)GetValue(PieChartControl.CompletionValueProperty); }
        set { SetValue(PieChartControl.CompletionValueProperty, value); }
    }


    static PieChartControl()
    {
        DefaultStyleKeyProperty.OverrideMetadata(typeof(PieChartControl), new FrameworkPropertyMetadata(typeof(PieChartControl)));
        FrameworkPropertyMetadata propMetadataCompletion = new FrameworkPropertyMetadata();
        CompletionValueProperty = DependencyProperty.Register("CompletionValue", typeof(double), typeof(PieChartControl), propMetadataCompletion);
    }

    public PieChartControl()
    {
        this.DataContext = this;
    }

Code of the Window

<Window x:Class="Practice1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:Pie="clr-namespace:PieChart;assembly=PieChart"
        xmlns:diagnostics="clr-namespace:System.Diagnostics;assembly=WindowsBase"
        xmlns:local="clr-namespace:Practice1"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <local:ConverterPagesnbToPercent x:Key="ConverterPagesnbToPercent"/>
    </Window.Resources>

 <Grid Name="grid1">
    <Grid.RowDefinitions>
        <RowDefinition Height="100"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <DataGrid ItemsSource="{Binding}" AutoGenerateColumns="False" Grid.Row="1" >
        <DataGrid.Columns>
            <DataGridTextColumn
                Header="ProjectedNumChap"
                Width="SizeToCells"
                Binding="{Binding ProjectedNumChap}"/>

            <DataGridTemplateColumn>
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <Pie:PieChartControl  CompletionValue="{Binding Path=CompletedNumChap, diagnostics:PresentationTraceSources.TraceLevel=High}" />
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
            </DataGridTemplateColumn>

        </DataGrid.Columns>
    </DataGrid>

</Grid>

So the binding in the DataGridTextColumn works perfectly, but the same one in the DataGridTemplateColumn doesn’t.
Here’s the data i got back in the output, thx to the diagnostic:

System.Windows.Data Warning: 54 : Created BindingExpression (hash=16804014) for Binding (hash=2616333)
System.Windows.Data Warning: 56 :   Path: 'CompletedNumChap'
System.Windows.Data Warning: 58 : BindingExpression (hash=16804014): Default mode resolved to OneWay
System.Windows.Data Warning: 59 : BindingExpression (hash=16804014): Default update trigger resolved to PropertyChanged
System.Windows.Data Warning: 60 : BindingExpression (hash=16804014): Attach to PieChart.PieChartControl.CompletionValue (hash=42879999)
System.Windows.Data Warning: 65 : BindingExpression (hash=16804014): Resolving source 
System.Windows.Data Warning: 68 : BindingExpression (hash=16804014): Found data context element: PieChartControl (hash=42879999) (OK)
System.Windows.Data Warning: 76 : BindingExpression (hash=16804014): Activate with root item PieChartControl (hash=42879999)
System.Windows.Data Warning: 106 : BindingExpression (hash=16804014):   At level 0 - for PieChartControl.CompletedNumChap found accessor <null>
System.Windows.Data Error: 40 : BindingExpression path error: 'CompletedNumChap' property not found on 'object' ''PieChartControl' (Name='')'.    BindingExpression:Path=CompletedNumChap; DataItem='PieChartControl' (Name=''); target element is 'PieChartControl' (Name=''); target property is 'CompletionValue' (type 'Double')
System.Windows.Data Warning: 78 : BindingExpression (hash=16804014): TransferValue - got raw value {DependencyProperty.UnsetValue}
System.Windows.Data Warning: 86 : BindingExpression (hash=16804014): TransferValue - using fallback/default value '0'
System.Windows.Data Warning: 87 : BindingExpression (hash=16804014): TransferValue - using final value '0'

For some reason it looks like it think that he should look for CompletedValue in the custom control, isn’t it? But I don’t get what i’m doing wrong though…

  • 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-25T11:10:32+00:00Added an answer on May 25, 2026 at 11:10 am

    Your PieChartControl is setting it’s DataContext property which is making it so you can’t bind outside of the Control without specifying the Source or RelativeSource.

    Remove the this.DataContext = this call, and add the following to your PieChartControl xaml.

    In your class definition at the top:

    xmlns:self="clr-namespace:Application.Controls.PieChartControl"

    and for each of your bindings, add:

    , RelativeSource={RelativeSource AncestorType={x:Type self:PieChartControl}}

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
i want to parse a xhtml file and display in UITableView. what is the
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.