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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:52:47+00:00 2026-06-01T00:52:47+00:00

Currently i have made a bar chart from a listbox from this example: http://weblogs.thinktecture.com/cnagel/2011/06/wpf-listbox-as-bar-chart.html

  • 0

Currently i have made a bar chart from a listbox from this example:
http://weblogs.thinktecture.com/cnagel/2011/06/wpf-listbox-as-bar-chart.html

What i want to do is change the color of the bars. My chart will have 5 bars and each have to be in a different color. Basically i want to change the Fill of the Rectangle.

EDIT:
The ItemsControl no longer seems to be getting any content and my chart is invisible.

     public class GrafiekBar : INotifyPropertyChanged
{
    private int value;
    private Brush fill = Brushes.Blue;

    public event PropertyChangedEventHandler PropertyChanged;

    private void NotifyPropertyChanged(String info)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(info));
        }
    }

    public List<GrafiekBar> GetDataGrafiek()
    {
        int[] getallen = new int[] { 3, 5, 8, 6, 2 };
        List<GrafiekBar> list = new List<GrafiekBar>();

        for (int i = 0; i < getallen.Length; i++)
        {
            GrafiekBar bar = new GrafiekBar();
            bar.Value = getallen[i];
            bar.Fill = Brushes.Blue;
            list.Add(bar);
        }

        return list;
    }

    /// <summary>
    /// Implement INotifyPropertyChanged in  properties 
    /// http://msdn.microsoft.com/en-us/library/ms229614.aspx
    /// </summary>
    public int Value 
    {
        get { return this.value; }

        set
        {
            if (value != this.value)
            {
                this.value = value;
                NotifyPropertyChanged("Value");
            }
        }
    } 

    public Brush Fill
    {
        get { return this.fill; }

        set
        {
            if (value != this.fill)
            {
                this.fill = value;
                NotifyPropertyChanged("Fill");
            }
        }
    }

}

XAML:

<ObjectDataProvider x:Key="odpLbGrafiek" ObjectType="{x:Type myClasses:GrafiekBar}" MethodName="GetDataGrafiek"/>
    <ObjectDataProvider x:Key="odpLbGrafiekColors" ObjectType="{x:Type myClasses:GrafiekBar}" MethodName="Fill"/>


<DataTemplate x:Key="GrafiekItemTemplate">
        <Border Width="Auto" Height="Auto">
            <Grid>
                <Rectangle x:Name="recGrafiek" Fill="{Binding Source={StaticResource odpLbGrafiekColors}}" StrokeThickness="0"  
                    Height="45" Width="{Binding}" Margin="13.2" 
                    HorizontalAlignment="Right" VerticalAlignment="Bottom">
                    <Rectangle.LayoutTransform>
                        <ScaleTransform ScaleX="20" />
                    </Rectangle.LayoutTransform>
                </Rectangle>
            </Grid>
        </Border>
    </DataTemplate>


 <ItemsControl x:Name="icGrafiek"  
                 Margin="0" 
                 ItemsSource="{Binding Source={StaticResource odpLbGrafiek}}"
                 ItemTemplate="{DynamicResource GrafiekItemTemplate}" 
                 Grid.RowSpan="5" 
                 Grid.Column="1" Background="{x:Null}" HorizontalAlignment="Left" RenderTransformOrigin="0.5,0.5"
                 >
            <ItemsControl.RenderTransform>
                <TransformGroup>
                    <ScaleTransform/>
                    <SkewTransform/>
                    <RotateTransform Angle="180"/>
                    <TranslateTransform/>
                </TransformGroup>
            </ItemsControl.RenderTransform>
        </ItemsControl>

Best regards.

  • 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-06-01T00:52:48+00:00Added an answer on June 1, 2026 at 12:52 am

    You should always avoid direct interaction with the controls used for templating, instead bind everything you need to change to your item, then edit the property in question on the item.

    Instead of using just the values you will need a collection of more complex objects, at the very least they need two properties:

    public class Bar : INotifyPropertyChanged
    {
        public double Value { get; set; } // Implement interface in those properties for binding
        public Brush Fill { get; set; }
    }
    

    (Implementing INPC)

    <!-- in the template -->
    <Rectangle Width="{Binding Value}" Fill="{Binding Fill}" .../>
    
    var bar = (Bar)lbGrafiek.Items.CurrentItem;
    bar.Fill = Brushes.Red;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made this centered navigation bar, and I wanted to add a :active
I currently have a community site that I run that is made up of
We currently have code like this: Dim xDoc = XDocument.Load(myXMLFilePath) The only way we
I have a serverside function: string foo(string input_string); for example: foo(bar) returns baz and
I have a contest running, and to look at the results I've made this
I currently have a grid made out of square DIVs (200px x 200px each).
I have made the MVC Music Store through the tutorials and I'm now currently
I currently have made a UnitOfWork implementation which wraps both the database connection and
I have created a branch like this svn copy svn+ssh://foo.bar/svn/myproject/trunk svn+ssh://foo.bar/svn/myproject/branches/feature-x I then proceeded
For several applications I made for my current client I have shared user accounts.

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.