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

  • SEARCH
  • Home
  • 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 5998567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:25:29+00:00 2026-05-23T00:25:29+00:00

I have a collection of custom data objects that I display in DataGrid. The

  • 0

I have a collection of custom data objects that I display in DataGrid. The columns are created dynamically on runtime. Some of the columns are TemplateColumns which display the value as a progressbar with respective text in the TextBlock; the brogressbar itself is defined from Style:

private string CreateProgressBarColumnTemplate(string fieldName)
{
    StringBuilder CellTemp = new StringBuilder();
    CellTemp.Append("<DataTemplate ");
    CellTemp.Append("xmlns='http://schemas.microsoft.com/winfx/");
    CellTemp.Append("2006/xaml/presentation' ");
    CellTemp.Append("xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'>");
    CellTemp.Append(String.Format("<ProgressBar Margin=\"0,1,0,0\" MinWidth=\"100\" MaxWidth=\"Infinity\" MaxHeight=\"Infinity\" Width=\"Auto\" Height=\"Auto\" HorizontalAlignment=\"Stretch\"  VerticalAlignment=\"Stretch\" Value=\"{{Binding {0}}}\" Style=\"{{StaticResource ProgressBarStyle}}\"/>", fieldName));
    CellTemp.Append("</DataTemplate>");
    return CellTemp.ToString();
}

private DataGridTemplateColumn CreateProgressBarTemplateColumn(string fieldName, string columnHeader)
{
    DataGridTemplateColumn column = new DataGridTemplateColumn();
    column.CanUserSort = true;
    column.CanUserResize = false;
    column.Header = columnHeader;
    column.CellTemplate = (DataTemplate)XamlReader.Parse(CreateProgressBarColumnTemplate(fieldName)); //display template
    return column;
}
<Style x:Key="ProgressBarStyle" TargetType="ProgressBar">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="ProgressBar">
                <Border BorderBrush="#BBC6C4" BorderThickness="1" CornerRadius="5" Padding="1">
                    <Grid x:Name="PART_Track" >
                        <Rectangle x:Name="PART_Indicator" HorizontalAlignment="Left" RadiusX="5" RadiusY="5">
                            <Rectangle.Fill>
                                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                    <GradientStop Color="#FF1D5666" Offset="1"/>
                                    <GradientStop Color="#FF09B6FF"/>
                                </LinearGradientBrush>
                            </Rectangle.Fill>
                        </Rectangle>
                        <TextBlock FontFamily="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}, Path=FontFamily}" 
                                   FontSize="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}, Path=FontSize}" 
                                   FontWeight="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}, Path=FontWeight}" 
                                   TextAlignment="Center" 
                                   Background="Transparent" 
                                   DataContext="{TemplateBinding Value}" 
                                   Foreground="{Binding Converter={StaticResource ValueToColor}}" x:Name="ProgressText" 
                                   Margin="0,-3,0,0" 
                                   Text="{Binding Converter={StaticResource DoubleToPercentage}}"
                                   />
                    </Grid>              
                </Border>       
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

As you can see, the TextBlock DataContext is set to Value property of progressbar and the TextBlock.Text is set from it.

The problem is that Value property can not be higher that MaxValue (Value seems to be set to MaxValue if I try assigning greater value), and my TextBlock.Text will always show 100% even if the actual cell value is greater than this.

The problem is, how do I bind TextBlock.Text property to actual cell value (the property on my custom data object, which is dynamic) and not to a progressbar?

  • 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-23T00:25:30+00:00Added an answer on May 23, 2026 at 12:25 am

    You can use the ProgressBar.Tag property to proxy the value to the TextBlock in the ControlTemplate. But really, this should be a custom control (i.e. MyProgressBar) which exposes a new dependency property (i.e. Text).

    To use the Tag, you’d add:

    CellTemp.Append(String.Format("<ProgressBar ... Tag=\"{{Binding {0}}}\" ... />", fieldName));
    

    The bind your TextBlock to it:

    <TextBlock ... DataContext="{TemplateBinding Tag}" ... />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a custom collection class that I am trying to bind to
I have a large collection of custom objects that I have retrieved from a
Background I have a custom collection that is binded to the datagridview this.datagridview.DataSource =
I have a WCF service that needs to expose a custom collection to it's
If I where to have a Queue holding a collection of objects (Custom object,bool,bool,bool,bool)
So I have a collection of objects that may be of multiple type. For
I have a custom object that implements INotifyPropertyChanged. I have a collection of these
I have this code for serializing my custom collection of UserData Objects. However the
I have a ValidationAttribute that I have created which is shared between the Server,
I have a my custom collection derived from List(.MyItem.) I want to trace if

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.