Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to format a string in XAML where a binding is being used?

In WPF, I could do something like this:

<TextBlock Text="{Binding Products.Count, StringFormat='{0} Products'}"

What is the equivalent in Windows 8 / WinRT, as this syntax is no longer supported?

like image 283
Robert Seder Avatar asked Sep 01 '12 15:09

Robert Seder


People also ask

How do I format a string in XAML?

Notice that the formatting string is delimited by single-quote (apostrophe) characters to help the XAML parser avoid treating the curly braces as another XAML markup extension. Otherwise, that string without the single-quote character is the same string you'd use to display a floating-point value in a call to String.

How does binding work in XAML?

Data binding is a mechanism in XAML applications that provides a simple and easy way for Windows Runtime Apps using partial classes to display and interact with data. The management of data is entirely separated from the way the data is displayed in this mechanism.

What is binding path in WPF?

Binding path syntax. Use the Path property to specify the source value you want to bind to: In the simplest case, the Path property value is the name of the property of the source object to use for the binding, such as Path=PropertyName . Subproperties of a property can be specified by a similar syntax as in C#.

What is string format in Java?

In java, String format() method returns a formatted string using the given locale, specified format string, and arguments. We can concatenate the strings using this method and at the same time, we can format the output concatenated string. Syntax: There is two types of string format() method.


1 Answers

You can use this:

<TextBlock>
    <Run Text="{Binding Path=Products.Count}" />
    <Run Text=" Products" />
</TextBlock>
like image 135
Jakub Krampl Avatar answered Oct 21 '22 12:10

Jakub Krampl