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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:34:55+00:00 2026-06-04T04:34:55+00:00

i created a converter to bind the foreground to a special value and change

  • 0

i created a converter to bind the foreground to a special value and change it but it takes always val as null:

public class PositionConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        //string vall;
        //TextBlock txt= TextBlock.TextProperty(

        var val = value as TextBlock;
        if (val != null)
        {
            if (val.Text.StartsWith("-"))
            {
                return new SolidColorBrush(Colors.Red);

            }
            else
            {
                return new SolidColorBrush(Colors.Green);
            }
        }
        return new SolidColorBrush(Colors.Red);
    }

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }
           <TextBlock FontSize="28"  x:Name="solde" TextWrapping="Wrap"  >
           <Run Text="        Solde : " Foreground="Black"/>
           <Run Text="{Binding amount}" Foreground="{Binding amount, Converter=               {StaticResource PositionConverter}}" Language="fr-FR"/>
             </TextBlock>
  • 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-04T04:34:56+00:00Added an answer on June 4, 2026 at 4:34 am

    value is the value involved in the binding (in your case: amount), not the control. Therefore, casting it to TextBlock will never work.

    You can try this instead:

    public class PositionConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {          
            if (value == null)
            {
                return new SolidColorBrush(Colors.Red);
            }
    
            if (value.ToString().StartsWith("-"))
            {
                return new SolidColorBrush(Colors.Red);                   
            }
    
            return new SolidColorBrush(Colors.Green);
        }
    
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a converter that takes a decimal value and converts it to a
I created a simple Converter to concatenate the text of four TextBoxes in my
I have a Custom ListView created from XML Layout. I want to bind that
My class is like this, public class Person : DynamicObject { public string Name
Is a separate WPF value converter object instantiated for each binding that a particular
I created one program with pygame, imageGrab and sockets but it doesn't work. It
I bind a collection ObservableCollection<Foo> to a dependency property on my controller, but I
Hi I'm trying to create a converter to Convert my images in a database
I decided to create a currency converter in Java, and have it so that
I created a text area on my stage using the text tool, then converted

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.