Giving value to a Point
Point class constructor problems can be caused by regional settings. Dot vs. comma stuff: http://silverlight.net/forums/t/4142.aspx
I’m still hopeless!!!
Solution 1Can’t really call it a solution. Just inverses the problem..
double x = Convert.ToDouble("11,5");
double y = Convert.ToDouble("0,44");
Point TestPoint = new Point(x,y);
Solution 2
Didn’t really work for me either. I guess it’s my fault, but i had problem with constructing Point from results of calculations:
http://www.codeproject.com/csharp/floatparse.asp
Solution 3My solution. It’s cool until you use it to create a new point. But as you try to give value to a Point property, like GradientOrigin it fails.
double x;
string _x = (2.0 / 3.0).ToString(System.Globalization.CultureInfo.InvariantCulture);
x = double.Parse(_x, System.Globalization.CultureInfo.InvariantCulture);
double y;
string _y = (1.0 / 2.0).ToString(System.Globalization.CultureInfo.InvariantCulture);
y = double.Parse(_y, System.Globalization.CultureInfo.InvariantCulture);
Point TestPoint = new Point(x,y);
Extensive tests with September refresh
(with no results…)
public void LampMove(double x, double y)
{
// Moving the center of the radial brush
// Coverting coordinates to relative valuesdouble xRelative = x / DarknessOverlay.Width;
double yRelative = y / DarknessOverlay.Height;CultureInfo CurrentCulture = CultureInfo.CurrentCulture;
CultureInfo InvariantCulture = CultureInfo.InvariantCulture;string _x;
string _y;// Simple value giving
// hu-hu regional settings: from ((0,05),(0,13)) it gave 0,5
// en-us regional settings: works
Lamp.Center = new Point(xRelative, yRelative);// Value giving using Convert with CurrentCulture
// hu-hu regional settings: from ((0,05),(0,13)) it gave 0,5
// en-us regional settings: works
_x = xRelative.ToString();
_y = yRelative.ToString();
Lamp.Center = new Point(Convert.ToDouble(_x,CurrentCulture),Convert.ToDouble(_y,CurrentCulture));// Value giving using Convert with InvariantCulture
// hu-hu regional settings: from ((0,05),(0,13)) it gave 0,5
// en-us regional settings: works
_x = xRelative.ToString();
_y = yRelative.ToString();
Lamp.Center = new Point(Convert.ToDouble(_x, InvariantCulture), Convert.ToDouble(_y, InvariantCulture));// Value giving using Convert with InvariantCulture
// and ToString with CurrentCulture
// hu-hu regional settings: error: it doesn't take the doubles' points (commas in this culture) into account. uses numbers without leading nulls.
// en-us regional settings: works
_x = xRelative.ToString(CurrentCulture);
_y = yRelative.ToString(CurrentCulture);
Lamp.Center = new Point(Convert.ToDouble(_x, InvariantCulture), Convert.ToDouble(_y, InvariantCulture));// Value giving using Convert with InvariantCulture
// and ToString with InvariantCulture
// hu-hu regional settings: from ((0,05),(0,13)) it gave 0,5
// en-us regional settings: works
_x = xRelative.ToString(InvariantCulture);
_y = yRelative.ToString(InvariantCulture);
Lamp.Center = new Point(Convert.ToDouble(_x, InvariantCulture), Convert.ToDouble(_y, InvariantCulture));// Value giving using Parse with CurrentCulture// Value giving using Parse with InvariantCulture
// hu-hu regional settings: error: from ((0,05),(0,13)) it gave 0,5
// en-us regional settings: works
_x = xRelative.ToString();
_y = yRelative.ToString();
Lamp.Center = new Point(double.Parse(_x, CurrentCulture), double.Parse(_y, CurrentCulture));
// hu-hu regional settings: error: it doesn’t take the doubles’ points (commas in this culture) into account. uses numbers without leading nulls.
// en-us regional settings: works
_x = xRelative.ToString();
_y = yRelative.ToString();
Lamp.Center = new Point(double.Parse(_x, InvariantCulture), double.Parse(_y, InvariantCulture));
// Value giving using Parse with InvariantCulture
// and ToString with CurrentCulture
// hu-hu regional settings: error: it doesn’t take the doubles’ points (commas in this culture) into account. uses numbers without leading nulls.
// en-us regional settings: works
_x = xRelative.ToString(CurrentCulture);
_y = yRelative.ToString(CurrentCulture);
Lamp.Center = new Point(double.Parse(_x, InvariantCulture), double.Parse(_y, InvariantCulture));
// Value giving using Parse with InvariantCulture
// and ToString with InvariantCulture
// hu-hu regional settings: error: the point of the first double works as comma
// en-us regional settings: works
_x = xRelative.ToString(InvariantCulture);
_y = yRelative.ToString(InvariantCulture);
Lamp.Center = new Point(double.Parse(_x, InvariantCulture), double.Parse(_y, InvariantCulture));
}
I really should give up on this!
I got the idea to change the CurrentCulture of the thread, just to find out it doesn’t work (of course I took the thirty minutes of breakpoint craze to find it out first hand).
The answer:
http://silverlight.net/forums/p/1497/3821.aspx
For your laugh:
// Simple value giving
// and temporary changing thread culture
CultureInfo OldCulture = CultureInfo.CurrentCulture;
CultureInfo NewCulture = CultureInfo.CreateSpecificCulture("en-US");
// this line breaks:
System.Threading.Thread.CurrentThread.CurrentCulture = NewCulture;
Lamp.Center = new Point(xRelative, yRelative);
System.Threading.Thread.CurrentThread.CurrentCulture = OldCulture;
[…] draw and compile < Stromy Weather Giving value to a Point […]
[…] clash between decimal separators, double values and application culture already made Point type a victim. Today I found abound another […]
And you do not accidentally from Moscow?
No, I’m from Budapest. Why do you ask?