0

I am trying to figure out a way to show the user the download progress like this:

  • 17.38/50Mb's

But I need to bidnd through xaml with StringFormat

1 Answers1

1

To use StringFormat in XAML,

<StackPanel Orientation="Horizontal">    
    <TextBlock Text="{Binding DownloadSizeInMB, StringFormat={0:0.00}}" />
    <TextBlock Text="/" />
    <TextBlock Text="{Binding TotalSizeInMB, StringFormat={0:0.00}}" />
    <TextBlock Text="Mb's" />
</StackPanel>

But these comes with some Margin between the TextBlocks.

I would suggest you use MultiBinding instead.

kennyzx
  • 12,845
  • 6
  • 39
  • 83
  • Sorry for the long wait thanks for the quick answer might you know how to make it so that is only shows two decimal places ? like "5.34/25.70" –  Oct 01 '17 at 09:22
  • @JosefLintz {0:0.00} is the format that produces two decimal places. What is the result now? – kennyzx Oct 01 '17 at 09:26
  • The thing is that I can't use it as binding I need to use it inside the multibinding. Like this- `StringFormat="{}{0:F1}{1:F1}"` but everytime I use it it pauses the program and continue until the extraction process start (It works in the background but unresponsive) –  Oct 01 '17 at 09:34
  • try "{}{0:F2}{1:F2}", please refer to [this answer](https://stackoverflow.com/a/11014784/815938), F2 means 2 decimal digits. – kennyzx Oct 01 '17 at 09:39
  • The problem is that I am sure the StringFormat works, but it pasuses the program until the download is finished. –  Oct 01 '17 at 09:43
  • Oh! I see! Try NOT to update the progress too frequently. You may have updated the progress property after download some tiny block of data (a few KBs), this way, the UI will be too busy update itself, it may have to replaint itself for thousands of times before the download finishes... Think about update the progress property once only after you download 1MB. – kennyzx Oct 01 '17 at 09:47
  • Every time you update the value of the progress, the databinding will force the UI to update. You should not update UI too frequently like 1000 times per second, that will freeze it up. – kennyzx Oct 01 '17 at 09:50
  • I understand I will keep that in mind but What I don't understand is how can it write numbers like 5.9889128/28.5288818 without pausing but when I add a stringFormat suddenly it causes the UI to stop –  Oct 01 '17 at 09:52
  • Interesting, please raise a new question regarding this issue. Our discussion is too far away from the original question. – kennyzx Oct 01 '17 at 09:55