0
我正在使用WPF數據綁定。如果我指定StringFormat={}{0:C}
,我可以格式化該號碼。但是,如果我用StringFormat={}{0:X2}
,它會給給以下異常:WPF Databinding StringFormat不支持十六進制格式?
System.Windows.Data Error: 6 : 'StringFormat' converter failed to convert value '10' (type 'Double'); fallback value will be used, if available. BindingExpression:Path=Value; DataItem='Slider' (Name='SliderG'); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String') FormatException:'System.FormatException: Format specifier was invalid.
at System.Number.FormatDouble(Double value, String format, NumberFormatInfo info)
at System.Double.ToString(String format, IFormatProvider provider)
at System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String format, Object[] args)
at System.String.Format(IFormatProvider provider, String format, Object[] args)
at System.Windows.Data.BindingExpression.ConvertHelper(IValueConverter converter, Object value, Type targetType, Object parameter, CultureInfo culture)'
'WpfApplication1.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Numerics\v4.0_4.0.0.0__b77a5c561934e089\System.Numerics.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
得到任何人的任何想法?
是否有任何簡單的方法可以在XAML標記中進行類型轉換? –
我不這麼認爲;通常你會爲你的數據上下文添加一個新的只讀屬性來爲你執行類型轉換。 –
令人失望。我可以有我自己的類型轉換器,但我希望框架可以提供一些簡單的語法來執行顯式類型轉換 –