Quantcast
Channel: Akash Kava » Unit
Viewing all articles
Browse latest Browse all 2

Measurement Unit Conversion for WPF and Silverlight

$
0
0

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.

  1. Which allows Developer to adhere to one standard unit.
  2. Which allows users to choose unit of their own choice.
  3. See the conversion while editing the value.

MeasurementControlPart1

 

The following sample code displays how to use these unit converters in Silverlight and WPF.

Properties

Each of the measurement unit converter controls has four properties as mentioned below.

DisplayValue Property:

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.

DisplayUnitID 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.

ValueUnitID Property:

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.

Value Property:

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.

Example:

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.

Live Sample:

Click here to view live sample in Silverlight.

Download Demo:

Click here to download the demo version of UI Atoms.

Share


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images