/ Published in: C#

reference: [blogs.msdn](http://blogs.msdn.com/b/bencon/archive/2006/05/10/594886.aspx)
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// XAML <Window.Resources> <local:TwoDecimalConverter x:Key="decConverter" /> </Window.Resources> ... <Slider x:Name="slider1" TickFrequency="1" TickPlacement="BottomRight" /> <TextBox Text="{Binding ElementName=slider1, Path=Value, Converter={StaticResource decConverter}}" /> // C# public class TwoDecimalConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { double val; if (value == null) return "0"; if (!Double.TryParse(value.ToString(), out val)) return "0"; return val.ToString("F2"); } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { } }
Comments
