Scientific calculations often require measurement unit conversion and demand high accuracy. Although it may be very easy to google around the web and get some formula, however when we looked into SI units and its Unit Guide, then we realized that even units with same name have little different value in different countries and continents.
So we decided to bring them all into User Interface control for WPF and Silverlight.
- Which allows Developer to adhere to one standard unit.
- Which allows users to choose unit of their own choice.
- See the conversion while editing the value.
The following sample code displays how to use these unit converters in Silverlight and WPF.
Each of the measurement unit converter controls has four properties as mentioned below.
This is the editable value displayed in the text box, and user can directly modify this value by either using up/down arrow buttons or by typing in the value. The display value works in conjunction with the type of unit that is selected in Display Unit ID property.
Every measurement unit has different ID assigned by our developers to uniquely identify alpha numeric ID within the set of units. For example, meter and centimeter are IDs of Length. However you do not have to remember these IDs, when you edit your UI in Visual Studio, you can configure these IDs in the property editor. End user can visually modify Display Unit in order to retrieve and enter value in the desired unit.
The DisplayUnitID is attached to DisplayValue, similarly the underlying actual value is attached with ValueUnitID property. This Unit ID is usually set to a constant throughout the lifetime of the application and is already defaulted to SI unit. e.g. for Length, it is set to meter. We recommend you to change this only if your base unit requirement is something different then SI unit. This unit can not be changed by end user it can only be programmed in the code at design time.
The value property is something which you are interested saving in the database and use it as base value. This is the converted value of unit ValueUnitID specified from display value of display unit.
In the first control in the above picture, Display Value is 100, Display Unit is Fathom, Value Unit is meter, so converted value in meter is 182.8804.
Click here to view live sample in Silverlight.
Click here to download the demo version of UI Atoms.
Here is quick update for the following error,
Message=System.Reflection.AmbiguousMatchException: Ambiguous match found.
That may start popping up after you install Silverlight 4 RC or later version and its quite annoying when Silverlight does not offer any detail about the error. One of the most annoying factor in silverlight is, for every parse exception Line Number and Line Position are always zero.
I started analyzing my code and try to understand what went wrong, it took half an hour to figure out the root cause. And following is the result,
I had a derived TextBox class of silverlight and had a property named “Watermark”, however I did compile everything against Silverlight 3 only, but over curiosity I had installed Silverlight 4 RC, which has TextBox with a property named “Watermark” with type as object.
No Side by Side in Silverlight
That is bad news, because if tomorrow there is one update by Microsoft, and you are away from your desk, all of sudden support calls will start piling up. Because the new update will have few things that will raise all unexpected errors without warnings. So if you have Silverlight 3 app, if you dont plan to upgrade to 4, Silverlight will not run side by side and it will cause problems. So you will always have to keep on upgrading Silverlight apps!!
This occurs when you have a property in your class as well as in the base class (usually we always will be careful to avoid this) with different type. However I dont know what exactly will happen if you have property with same type and name in base as well as child class, but it looks to me as if this is just a parse exception. Silverlight may load values correctly.
I know this is what you are looking for, but it isnt easy, what you have to find out is, if any of your class has any property whose name exactly matches with name of property defined in its base class and higher in inheritance chain. If you have same name but different type, this error will occur, it may also occur if you have property written with new keyword. It will not occur on inherited property.
Please also have a look at upcoming, rapid business form development on WPF as well as Silverlight. Please click here to check the preview.