Prev: Excel 2007 Addin using C#
Next: Access Violation when SetWindowHookEx Hook-Procedure runs after a while,...
From: Wonko the Sane Wonko the on 22 Jan 2009 10:36 Hello All, I am having an issue with decimal separators and localization. Assume that I have set Regional Settings to, say, German, where the decimal separator is a comma. When I bind directly to a Double value, the value shows up correctly. However, if I go through a data converter, the value is always coming back with a decimal point (period). See abbreviated code example below. Thanks, WtS <!-- In XAML - DataContext set to a DataTable --> <TextBlock Text={Binding Converter={StaticResource SomeConverter}, ConverterParameter=SomeKey} /> // IValueConverter class example - usually has more error checking, etc. class SomeConverter : IValueConverter { public object Convert(...) { DataTable dt = (DataTable) value; String key = parameter.ToString(); DataRow [] rows = dt.Select("Data = '" + key + "'"); return Double.Parse(rows[0]["CurrentValue"].ToString()); } }
From: Linda Liu[MSFT] on 23 Jan 2009 04:20
Hi WtS, I performed a test on this issue. In my test, I set the Region Settings to German(Germany) and bind a TextBlock's Text property directly to a Double value. However the value still shows up with a decimal point(period). Anyway, a solution to your problem is to call the Double.ToString method and pass the current CultureInfo to it. The following is the modified value converter: class SomeConverter : IValueConverter { public object Convert(...) { DataTable dt = (DataTable) value; String key = parameter.ToString(); DataRow [] rows = dt.Select("Data = '" + key + "'"); System.Globalization.CultureInfo currentCI = System.Threading.Thread.CurrentThread.CurrentCulture; if(targetType == typeof(string)) { return ((double)rows[0]["CurrentValue"]).ToString(currentCI); } else { return Double.Parse(rows[0]["CurrentValue"].ToString()); } } } Please try my suggestion to see if it works. If you have any question, please feel free to let me know. Sincerely, Linda Liu Microsoft Online Community Support Delighting our customers is our #1 priority. We welcome your comments and suggestions about how we can improve the support we provide to you. Please feel free to let my manager know what you think of the level of service provided. You can send feedback directly to my manager at: msdnmg(a)microsoft.com. ================================================== Get notification to my posts through email? Please refer to http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif ications. Note: The MSDN Managed Newsgroup support offering is for non-urgent issues where an initial response from the community or a Microsoft Support Engineer within 1 business day is acceptable. Please note that each follow up response may take approximately 2 business days as the support professional working with you may need further investigation to reach the most efficient resolution. The offering is not appropriate for situations that require urgent, real-time or phone-based interactions or complex project analysis and dump analysis issues. Issues of this nature are best handled working with a dedicated Microsoft Support Engineer by contacting Microsoft Customer Support Services (CSS) at http://msdn.microsoft.com/subscriptions/support/default.aspx. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. |