Quantcast
Channel: User Liyun Zhang - MSFT - Stack Overflow
Viewing all articles
Browse latest Browse all 446

Answer by Liyun Zhang - MSFT for How to format Label's Text with StringFormat when the label is set as the binding source of slider?

$
0
0

Actually, using the Slider as the binding source is better choice. The Text="{Binding StringFormat='{0:F2}'}" will not work for the binding source. And I can't find any way can do that in xaml.

But you can try to format the label's text in code behind when the label is binding source. Such as:

In the xaml:

<Label x:Name="label" PropertyChanged="label_PropertyChanged"/><Slider Value="{Binding Text,Source={Reference label}}" WidthRequest="300"/>

And in the code behind:

private void label_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) {     if(e.PropertyName == "Text")     {         (sender as Label).Text = String.Format("{0:0.##}",Convert.ToDouble((sender as Label).Text));     } }

Viewing all articles
Browse latest Browse all 446

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>