icsharpcode / WpfDesigner

The WPF Designer from SharpDevelop
MIT License
949 stars 251 forks source link

Removed hardcoded culture #34

Closed awraae closed 7 years ago

awraae commented 7 years ago

In the DesignSurface class the CurrentCulture is explicitely set to "InvariantCulture".

The result of this is that values presented in the PropertyGrid is always formatted using the InvariantCulture. Regional settings are ignored.

The hardcoded culture has in my case also caused a problem because I need to localize the application in which I integrate WpfDesigner.

I have investigated why the culture is explicitely set. I have only found a problem in NumberEditor where the entered value was always validated using InvariantCulture. I have fixed this so it now validates using CurrentCulture.

I certify that I own, and have sufficient rights to contribute, all source code and related material intended to be compiled or integrated with the source code for the WPF Designer open source product (the "Contribution"). My Contribution is licensed under the MIT License.

jogibear9988 commented 7 years ago

I'm not sure if we should change this, or maybe we should add a setting to enable/disable. Because in XAML you also have to use the same number format (not matter in wich culture you are)

But that "Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;" is wrong. I don't think it's a good Solution. I'll look into this when I've time...

awraae commented 7 years ago

Thanks for your quick response.

I believe that these changes will not affect how XAML is rendered or parsed.

Just to elaborate, the pull request consist of two changes:

  1. Removed hardcoded culture in DesignSurface
  2. Fixed NumberEditor so that it works with any culture

The code change in NumberEditor should only affect how a number value is formatted in the editor and which input format the editor accepts.

I might of course overlook something.

FYI: The hardcoded culture was introduced with the PropertyGrid in 2008.

Thanks :-)

jogibear9988 commented 7 years ago

I know that it not affects xaml, but I don't like that in some cultures then you have a comma in the propertygrid and a dot in the xaml. but some people may like this. for that i'd like if it's configurable! but i dislike the set of the ui culture that we do atm. i think about this a little bit more

awraae commented 7 years ago

Thanks for clarifying. I understand your point now.

Actually I think it is already "configurable" in the pull request.

When integrating WpfDesigner in your own application you can just set the CurrentCulture and the PropertyGrid will behave based on that. So if you for example explicitely set InvariantCulture, it will behave as it does now.

I have two suggestions that you can consider:

1. Let the CurrentCulture control how values are formatted in the PropertyGrid (how it works in the pull request).

2. Change the NumberEditor to always use InvariantCulture. This way Number editor will always use the same NumberFormat to present and validate values.

The primary goal for me is to remove the line in DesignSurface where the CurrentCulture is set to InvariantCulture. This is because it prevents me from completing a localization task.

It is less important to me (personally) how the PropertyGrid works - however I like suggestion 1 the most.

However, in Visual Studio's Property Window for their Wpf Designer (and in Blend), it seems that they use an approach more like suggestion 2.

jogibear9988 commented 7 years ago

I will change the number editor!!

awraae commented 7 years ago

Thanks a lot!

jogibear9988 commented 7 years ago

The Number Editor uses now InvariantCulture without changeing UI Culture!