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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:12:34+00:00 2026-05-28T02:12:34+00:00

I have a progress bar that I want to change color depending on a

  • 0

I have a progress bar that I want to change color depending on a boolean value; true is green and false is red. I have code that seems like it should work (it returns the correct value when I bind it to a textbox) but not when it’s the color property of the progress bar. The converter is defined as this (in App.xaml.cs since I want to access it anywhere):

public class ProgressBarConverter : System.Windows.Data.IValueConverter
{
    public object Convert(
        object o, 
        Type type, 
        object parameter, 
        System.Globalization.CultureInfo culture)
    {
        if (o == null)
            return null;
        else
            //return (bool)o ? new SolidColorBrush(Colors.Red) : 
            //                 new SolidColorBrush(Colors.Green);
            return (bool)o ? Colors.Red : Colors.Green;
    }

    public object ConvertBack(
        object o, 
        Type type, 
        object parameter, 
        System.Globalization.CultureInfo culture)
    {
        return null;
    }
}

I then add the following to the App.xaml (so it can be a global resource):

<Application.Resources>
    <local:ProgressBarConverter x:Key="progressBarConverter" />
    <DataTemplate x:Key="ItemTemplate">
        <StackPanel>
            <TextBlock Text="{Binding name}" Width="280" />
            <TextBlock Text="{Binding isNeeded, 
                          Converter={StaticResource progressBarConverter}}" />
            <ProgressBar>
                <ProgressBar.Foreground>
                    <SolidColorBrush Color="{Binding isNeeded, 
                             Converter={StaticResource progressBarConverter}}" />
                </ProgressBar.Foreground>
                <ProgressBar.Background>
                    <SolidColorBrush Color="{StaticResource PhoneBorderColor}"/>
                </ProgressBar.Background>
            </ProgressBar>
        </StackPanel>
    </DataTemplate>
</Application.Resources>

I added the following to MainPage.xaml to display them:

<Grid x:Name="LayoutRoot" Background="Transparent">
    <ListBox x:Name="listBox" 
             ItemTemplate="{StaticResource ItemTemplate}"/>
</Grid>

And then in MainPage.xaml.cs, I define a class to hold the data and bind it to the listBox:

namespace PhoneApp1
{
    public class TestClass
    {
        public bool isNeeded { get; set; }
        public string name { get; set; }
    }

    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            var list = new LinkedList<TestClass>();
            list.AddFirst(
                                new TestClass { 
                                    isNeeded = true, name = "should be green" });
            list.AddFirst(
                                new TestClass { 
                                    isNeeded = false, name = "should be red" });
            listBox.ItemsSource = list;
        }
    }
}

I’ve attached a minimal working example so it can just be built and tested. An image of the output is here:

enter image description here

It returns the values from the converter for the textbox but not the progress bar. When I run the debugger, it doesn’t even call it.

Thanks for any help!

  • 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-28T02:12:35+00:00Added an answer on May 28, 2026 at 2:12 am

    Try to modify your converter to return a SolidColorBrush and then bind directly to your ProgressBars Foreground property.

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

Sidebar

Related Questions

i have this code is a progress bar that fill with a red color
I have the basic jQueryUI progress bar code here; <script> $(function() { $(#progressbar).progressbar({ value:
Basic Goal is that i have four progress bar and want to run them
I have a WPF project using CM. I have a progress bar that I
All Gmail users should have already noticed that file upload progress bar has been
In the following code example, I want to change the color of the Foreground
I have a Control Template for Progress Bar in my Resource Dictionary. Complete code
I have a LinearLayout that will have a cancel button and a progress bar,
I want to Update the Progress bar in my application. I have created a
I want to have a progress bar which goes as a countdown from 10

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.