-1

I want to bind a string value with string format.

I have tried many ways but it didn't work.

Could anybody help me to solve this problem?

This is the way I am currently using, but I still want to use StringFormat.

How could I do this ?

<DiscreteObjectKeyFrame.Value>
    <MultiBinding Converter="{StaticResource DotConverter}">
         <Binding Path="LoadingStringShow"/>
         <Binding>
             <Binding.Source>
                <sys:Int16>1</sys:Int16>
             </Binding.Source>
         </Binding>
    </MultiBinding>
</DiscreteObjectKeyFrame.Value>
Isma
  • 14,604
  • 5
  • 37
  • 51
Bing Feng
  • 71
  • 2
  • 11

1 Answers1

1

The best way to format a string is to do this in code.

You could use string.Format() or for C#6's new Feature: "Interpolated Strings" as shown below to format your string.

private string _name;
public string Name
{
    get {return $"My Name is {_name}";}
    set 
    {
        _name = value;
        //OnPropertyChanged("Name");
    }
}

Your Binding will then show: My Name is <valueofvariable>

Since your bindings name is LoadingStringShow I assume you want to display some kind of loading message.

Maybe this could also help:

<TextBlock Text="{Binding LoadingStringShow, StringFormat={}{0}%}" />

or

<TextBlock TextAlignment="Center">
<TextBlock.Text>
    <MultiBinding StringFormat="{}{0} - {1}%">
         <Binding Path="LoadingStringShow" />
         <Binding Path="CurrentValue" />
    </MultiBinding>
</TextBlock.Text>

Reference 1

Reference 2

Felix D.
  • 4,811
  • 8
  • 38
  • 72