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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:43:06+00:00 2026-06-10T09:43:06+00:00

I have a TextBlock which is bound to an Integer property of my model.

  • 0

I have a TextBlock which is bound to an Integer property of my model. The TextBlock int property increases its count from 0 to 99. I first show TextBlocks 0-9 in a ListView.

If there are more than 10 TextBlocks, I want the first 10 TextBlocks numbered 0-9 to show as 00, 01 , 02.. 09. I can use the string.Format method in WPF to achieve this behavior. But if there are fewer than 10 TextBlocks they should be numbered as 0, 1, 2 — 9.

How can I achieve this behaviour? Can I use MultiBinding Converter? If yes, help me with a sample.

Here is the code:

<ListView ItemsSource= "{Binding}"> <!-- Binding to a collection which has the Tag Id property -->
  <Grid x:Name="TagNum_grid" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="1,3,0,0" Grid.Column="1" >
    <TextBlock x:Name="DefaultIDtextblock" Margin="1,0" Text="{Binding Path=TagID}" TextWrapping="Wrap" Foreground="#FFA0A0A0" />
  </Grid>
</ListView>
  • 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-10T09:43:08+00:00Added an answer on June 10, 2026 at 9:43 am

    As you mentioned, you could use MultiBinding, where the first value is the tag id and the second is the number of elements.

    First, define the value converter:

    public class MyConverter : MarkupExtension, IMultiValueConverter
    {
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            return this;
        }
    
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            int tagId = (int)values[0];
            int itemCount = (int)values[1];
    
            if (itemCount >= 10 && tagId < 10)
            {
                return "0" + tagId;
            }
    
            return tagId;
        }
    }
    

    Then bind the values, using the above converter

    <ListView ItemsSource="{Binding}">
        <Grid x:Name="TagNum_grid" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="1,3,0,0" Grid.Column="1" >
            <TextBlock x:Name="DefaultIDtextblock" Margin="1,0" TextWrapping="Wrap" Foreground="#FFA0A0A0" >
                <TextBlock.Text>
                    <MultiBinding Converter="{local:MyConverter}">
                        <Binding Path="TagID" />
                        <Binding Path="Items.Count" RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=ListView}" />
                    </MultiBinding>
                </TextBlock.Text>
            </TextBlock>
        </Grid>
    </ListView>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a ListView which contains objects bound from an collection. The representation of
I have Listbox which is bound to my view model. This view model has
I have a Silverlight Listbox bound to Observablecollection which shows up fine (first time)
I have a DataGridTemplateColumn that defines a TextBlock which has bound Background and Foreground
Lets say i have a TextBlock thats bound to a DateTime, is there any
I have a progress bar bound to 2 integer values - One is the
I have a textblock bound to an object. The 2-way binding works well and
I have a ListBox which is bound to a collection. When I add an
I have Datagrid which is bound to my Database <WpfToolkit:DataGrid Name=DataGrid1 Grid.Row=1 ItemsSource={Binding Path=MainSearchBinding}
I have a ListBox which is bound to ObservableCollection of LogMessages. public ObservableCollection<LogMessage> LogMessages

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.