Use StringFormat to add a string to a WPF XAML binding

后端 未结 4 1239
一向
一向 2020-11-28 04:14

I have a WPF 4 application that contains a TextBlock which has a one-way binding to an integer value (in this case, a temperature in degrees Celsius). The XAML looks like t

4条回答
  •  孤街浪徒
    2020-11-28 04:50

    In xaml

    
    

    In ViewModel, this way setting the value also works:

     public string CelsiusTemp
            {
                get { return string.Format("{0}°C", _CelsiusTemp); }
                set
                {
                    value = value.Replace("°C", "");
                  _CelsiusTemp = value;
                }
            }
    

提交回复
热议问题