-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>
3
  • May this help you ? Commented Sep 22, 2017 at 5:47
  • 1
    StringFormat doesn't apply to string values. Commented Sep 22, 2017 at 10:35
  • Is this solved ? Commented Oct 19, 2017 at 13:24

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.