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

The Archive Base Latest Questions

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

I’m trying to bind a list of objects to a list box. Each object

  • 0

I’m trying to bind a list of objects to a list box. Each object is shown in separate text block. But the problem is that each item should be shown in different format (e.g. Date, currency and so on). I want to store the format in a property of the object ant then set the format in the same binding expression where the value is set.
All the examples I’ve seen so far are showing how to set the string format by hard coding it:

<TextBlock Text="{Binding Value, Mode=OneWay, StringFormat=\{0:n3\}}"/>

I wonder if there is any way to bind the string format property like this:

<TextBlock Text="{Binding Value, Mode=OneWay, StringFormat={Binding myFormat}}"/>

Or maybe it can be achieved by using value converters. But again, is it possible to bind any property to the converter parameter like this:

<TextBlock Text={Binding Value, Converter={StaticResource myConverter}, ConverterParameter={Binding myFormat}}"/>

  • 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-17T00:29:19+00:00Added an answer on May 17, 2026 at 12:29 am

    Use a value converter that takes the whole object and have this converter access the Value and the Format properties of the object to generate the desired string.

    Example:-

     public class ValueFormatConverter : IValueConverter
     {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            IValueFormat vf = value as IValueFormat;
            if (vf != null)
                return String.Format("{0:" + vf.Format + "}", vf.Value);
            else
                throw new NotSupportedException("value does not implement IValueFormat");
        }
     }
    

    Have the objects in the list implement IValueFormat :-

    public interface IValueFormat
    {
        object Value { get; }
        string Format { get; }
    }
    

    Alternatively

    Since your object knows both its value and the format to use to present the value why not simply add a readonly FormattedValue property of type string to the object as well?

    If you are implementing INotifyPropertyChanged just make sure you fire PropertyChanged for “FormattedValue” whenever the value or the format has changed.

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

Sidebar

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.