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.
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.
Building line of business applications for over years, we realized that the Silverlight DataForm offers very small subset of features that are needed in the long run. We figured out the problem with form based applications, that frustrates developers. That is “Change Management”.
Although WPF/Silverlight does offer very customizable UI designing platform but when we go on the field to develop ling of business applications, we realize that initial development hardly takes any time but maintenance is very difficult.
Lets review the designing problems of panels such as Grid, StackPanel, Canvas etc.
Standard Form Design
Lets review standard form design that is expected, this is the layout that can not be made except canvas panel because there is no way we can support variable columns per row. If you notice, first two rows have 3 columns equally placed and last 2 rows have two columns equally placed. Every field has description at the bottom and red required asterisk (*).
Initial Form Design
The first draft of UI in any application is very simple and we probably do it in minutes.
Changes Requested
But the bigger problem always comes later on when changes are requested.
Atom Flexible Grid
This is the reason we created “AtomFlexibleGrid” which supports variable columns per row as displayed in the picture above. You can see that form and the flexible grid have a property called “RowLayout” which accepts comma separated cell values to be displayed per row. As displayed in the example below.
This is very helpful in quick design, but this also way to easy to manage when changes are requested.
- Intelligent Flow Layout with ability share multiple items in single row.
- No attributes required on any child items.
- Comma Separated “RowLayout” instantly renders variable column grid.
- E.g. 3,2,1 = 3 cells in first row, 2 cells in 2nd row and 1 cell in 3rd row with automatic spanning.
Benefits of Atom Flexible Grid over Canvas, Grid and Stack Panel
- Atom Form children are similar to Wrap Panel children, but Wrapping is completely customized via simple attributes.
- Its easy to move items around without changing lots of attributes, Grid is very powerful but changing grid children can be huge pain.
- Canvas is very easy to operate, but needs a powerful designer, once again changing layout can be very tedious job.
Form Field Layout
This is how individual components of Form Field are positioned within the Form Field. Collapsible panels are only visible if the content is provided. However in future more of such components will be available in Form Field to standardize the fields.
In next slide, you will see how the fields are positioned in the Form.
Change Management
Changing layout is extremely simple, as you can simply move your items up and down and change “RowLayout” text field to quickly review how it will look. No tedious drag and drop and no typing.
Live Form Demos
Click here to see live UI Atoms form demos for Silverlight.
Click here to download UI Atoms form demos for WPF.
Here at NeuroSpeech, we figured out the problem with forms based business applications that frustrates developers and change management is not only time consuming but its quite boring job to do.
Although WPF/Silverlight does offer very customizable UI designing platform but when we go on the field to develop ling of business applications, we realize that initial development hardly takes any time but maintenance is very difficult.
AtomForm has been designed to offer a standard rich business class user interface along with various advanced validation methods and the change management is very easy as “AtomFlexibleGrid” offers simple row layout concept that is offered nowhere today.
New update of UI Atoms 2010 v1.1 is now available, it includes fixes for Silverlight 4 and new controls as per following list.
Update 1.1
- UI Atoms is now upgraded to Silverlight 4, all binding workarounds have been removed.
- Six New Measurement Unit Controls have been added.
Measurement Unit Controls
Scientific measurements are complex and wide range of units are used everywhere, though conversions are not difficult but it is not possible to carry and remember all conversions and correct formulae.
UI Atoms 2010 v1.1 brings power of SI units conversion in set of following Measurement Unit Controls.
- AtomLengthEditor – helps in conversion of “Length” units.
- AtomTemperatureEditor – helps in conversion of “Temperature” units.
- AtomTimeEditor – helps in conversion of “Time” units.
- AtomVelocityEditor – helps in conversion of “Velocity” units.
- AtomVolumeEditor – helps in conversion of “Volume” units.
- AtomWeightEditor – helps in conversion of “Weight” units.
Currently, these controls offers very simple GUI as first draft, however you can see the number of units that are available that can help users view/edit the value in any desired unit.
This is Preliminary documentation about UI Delegation Pattern to create Clean and Reusable Data Components and UI Markups in a Business Application.
UI Delegation Pattern
I would call it simply divide and rule, UI Delegation Pattern is narrowing the focus towards piece of UI Element on the screen and have a UI component to fulfill every specific business needs.
User Interface is the direct connection between User and your business application, thought MVC, MVVM models exist, but they are found to be very useful in CRUD business applications, but when your application is more then CRUD and it involves complex UI and media / hardware interfaces for scientific and entertainment related applications, MVC/MVVM are little difficult to maintain over huge applications. This pattern is already in existence at many places.
Initial Rough Draft
This is initial rough draft, I intend to collect problems and solutions and then I want to give a good name to this pattern, for now I am calling this as “UI Delegation Pattern” however I don’t know whether it suits the name correctly or not. But your opinions are most welcome, if such pattern is already named and exists then I am sorry if I am unaware of it, but please suggest if you know so.
UI Markup vs. Editor Files
Earlier Visual Basic or Visual Studio would create .frm and resource files that would contain the contents of UI design created in “Designer/Editor” inside an IDE. These Editors would create code that is required to execute at runtime to create desired user interface. However since Editors would create code with specific style and pattern, these editor files are more or less very structured and they are less buggy. Of course too much of code will certainly make Editor very slow but at the same time, the consistency of UI code is preserved. But you are too much dependent on the Editor and complex UI could be very difficult to work in Editors.
Where else UI Markup based on xml, gives full freedom to user to create highly complex UI, but at the same time there is no consistency left as everyone writes code very differently. Markups gets piled into one file and it becomes way to difficult to maintain and understand how it works.
Identify Markup Noise
My first approach is to identify problems with Markup Noise, so lets identify what is markup noise. When I see any html, aspx, php or such web scripts, the most annoying things I discover that in spite great CSS and Modular programming support, the scripts becomes a big junk to maintain. Sure WPF / Silverlight are also text markups, hand coded markups becomes way to big junk to manage.
Bigger problem is to visualize markups as they become more complex. As more and more lines of code gets piled into markup, more time is spent understanding and troubleshooting the UI.
How to Reduce Markup Noise?
CSS brought a very useful way to reduce markup noise. Still lot of developers write inline styles and I hate to see that. Ideally nicely written code should have inline styles as small as possible.
Appearance Delegation
CSS comes under category of Appearance Delegation where your delegate the look and feel of your component to CSS file. In WPF and Silverlight the themes are styles are introduced and you must have all your styles and look and feel related code into resources only.
The markup containers (Connection Containers) such as Window / Page / User Control should not have any inbuilt styles at all.
Business Logic Delegation
This was not possible in plain html, but aspx, php etc did brought concept of server side controls where in you could inject business logic specific to components and reuse them. But these components (user controls / custom controls ) are only designed when they need to be reused, but even if it will be used only once, I would still suggest its better to have components as small as possible.
Example, Country Combo drop down , Gender Combo drop down, these boxes are nothing but set of options provided to user to select one of them. Now nobody makes specific custom controls for such items, but lets see a practical example.
Bad Markup Example
<Window.Resources> <XmlDataProvider x:Key="CountryData" XPath="/Countries"> <Countries xmlns=""> <Country CountryName="United States" CountryCode="US"/> <Country CountryName="United States" CountryCode="US"/> </Countries> </XmlDataProvider> </Window.Resources> <StackPanel> <ComboBox ItemsSource="{Binding Source={StaticResource CountryData}, XPath=Country}" DisplayMemberPath="@CountryName" SelectedValuePath="@CountryCode" /> <ComboBox> <sys:String>Male</sys:String> <sys:String>Female</sys:String> </ComboBox> </StackPanel>
Now this file defines a resource xml for Country List, and it is bounded by ComboBox to list countries and another ComboBox defines inline items to be displayed.
Let us identify “Controls and Connection Containers”.
The window, that hosts Country List and Gender Combo Boxes is “Connection Container” in which we should only host controls and connect inter dependent properties of every controls.
The Connection Container should not have any code that is not related to either any other items or business logic of the container at all.
List of Countries and Gender items are not at all related to anyone else except for the drop downs. This is pure markup junk where we have so many unnecessary information.
Solution
Define custom controls as shown below and see how small our markup becomes. And move Country List xml to some resource file.
public class CountryComboBox : ComboBox { public CountryComboBox() { this.DisplayMemberPath = "@CountryName"; this.SelectedValuePath = "@CountryCode"; Binding b = new Binding(); b.XPath = "Country"; b.Source = FindResource("CountryData"); this.SetBinding(ItemsSourceProperty, b); } }
public class GenderComboBox : ComboBox { public GenderComboBox() { this.ItemsSource = new string[] { "Male", "Female" }; } }
The final Markup.
<StackPanel> <local:CountryComboBox /> <local:GenderComboBox /> </StackPanel>
Wow, the markup is very clean now. Also the code is easy to understand.
Conclusion
The connection container (Window / Page / User Control) should only have interdependent declarations and should not have any items that are only specific to one control. It should be as clean as possible and it should execute all necessary business logic for the component.
Configuration items, even resource bindings should be avoided in Connection Containers. They should be narrowed down to custom controls as much as possible.
This increases readability, reusability and helps in troubleshooting while focusing by narrowing the target.
There is lot of buzz about LOB Business Form Layout for new platforms WPF & Silverlight, both capable of displaying rich content and extend functionalities of existing components so better then ever before.
XAML is better then earlier Rapid Form designers where you need to drag and drop within an IDE and the layout management becomes so complicated because no IDE is perfect. I remember upgrading from Visual Studio 2005 to 2008 and now 2010, most of our ASP.NET and WinForm projects would require lot of effort to work seamlessly in newer versions. The worst of all is, modifying layout without IDE becomes way to difficult.
In this presentation, I collected all important aspects of Business Form that we encounter in our day to day life and the complexity of forms make life terrible when clients request changes that takes hours on any IDE that sure breaks lot of code graphs and makes existing working system as completely useless code junk.
In UI Atoms, we at NeuroSpeech tried make set of components that are very easy to operate while going through tough change management.
Here is quick update for the following error,
System.Windows.Markup.XamlParseException occurred
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!!
AmbigiousMatchException
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.
Solution
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.
Looking at the innovation driving inside Silverlight, it is getting more attention then the former WPF. However having very similar syntax and .NET as base platform, both WPF and Silverlight are very different in approach, design and use. Today lot of developers live in dilemma of WPF vs Silverlight and it has now become a great trade off as similar to speed vs size.
Lets compare the need and features of both and make the trade off very easy to understand.
History of Microsoft Development Platform
We all loved Visual Basic, what did it provide? a rapid development platform to make quick business applications. By business applications I mean, the one to track your purchases, your activities which are just probably relational database and reports. Business Application makers didn’t have to worry about device drivers, system services, hardware and component versions.
Visual Basic provided very thin layer of application development for rapid turnaround time of small scale but huge in demand business applications. These applications require very less programming language expertise but more of business expertise. But it had limitations, you could not create a huge resource intensive application like CAD programs, Media editing programs, servers, games etc.
On other hand we had Visual C++, a huge development framework with possibility to do almost everything that was possible on Windows Operating System. Where you could fulfill need of any program, be it CAD, games, media editing, or servers etc.
But the development time required was very high, performance was great and the intelligence required to create system applications was very high. Getting talent to build such applications weren’t easy and even it is not easy today, because you need real in depth knowledge of how every part of the system functions. There is more dependency upon device drivers, component versions and there was no drag and drop.
Apart from any other platforms existed so far, Microsoft clearly and distinctly divided development into two major categories. Rapid vs System, or Native vs Thin applications.
Evolution of .NET
Ever since c# came into existence, we started seeing quick shift from tedious MFC/COM/ATL to c#, because all technologies were simply extension of c/c++ and each needed separate runtime to exist. Even still today, some of my components are written in ATL/COM and compiling them in newer version of Visual Studio is always pain. Compilation time is huge.
Where else, .NET based project took less time to compile, even the 1.0 versions are still in use and still in good shape.
Earlier it was expected that it will only replace the Visual Basic segment of programming, but somehow all devs started liking it and preferred it as an alternative to ATL/COM/MFC as its native capability and speed provided easy development and quick turnaround.
Windows Forms did provide an alternative to Visual Basic. But there was lack of more powerful, GUI interface in .NET. So came WPF. Not only this, .NET being neutral, the compiled apps are independent of 32 bit or 64 bit platforms.
Windows Presentation Framework
As we clearly see, Microsoft has its plan to make WPF as its primary GUI framework against all Win32 components. WPF is very easy to write as it is very simple XML, XML is very easy to read, and its very easy to organize, even the editors and compilers need less overhead in parsing and taking decisions based on XML.
The challenge here was to imitate almost everything that existed in Win32 inside WPF, and WPF became very feature rich, but once again it requires more intelligence to write complicated and big applications. Having talent already expert in HTML+JS area, and transforming them into WPF talent was little difficult.
Plus the way WPF was built, it was built more tight coupled with system operating system, just like the way MFC/ATL/COM were built. But WPF is very fast and very rich in features. It is now possible to write CAD, games and such high performance applications in WPF which can utilize latest hardware technologies.
And it is exact alternative for COM/ATL/MFC today.
Silverlight
Realizing that converting HTML+JS and Visual Basic devs to WPF was more challenging, silverlight pop in to existence, Which is very light weight, a smaller counterpart of WPF, although the syntax remains same, the ability to develop apps are limited in silverlight as it is not very tightly coupled with operating system.
However, you can develop apps pretty fast, but only focused on business logic, which here is one step ahead amongst all being platform independent. The devs are not required to have in depth knowledge of system, nor silverlight are more dependent on hardware, resources or other components.
But you cant develop high performance apps like CAD, games and media editing apps.
Indeed, it is an exact alternative for Visual Basic.
Conclusion
You need to choose WPF when you are creating any application of following type,
-
Interfaces with custom hardware.
-
You need to control memory and control the performance of app.
-
Create application that requires very high memory, CAD programs etc.
-
Connect to system components and used to manage system, hardware.
-
Want to connect to native system via COM/DLL interfaces.
-
Media (Audio/Video/Picture) editing applications.
-
Where your target audience can download and install .NET platform easily.
However you can use Silverlight for following alternative type of applications,
-
Provides smooth and quick animation on the web.
-
Make Rapid Business Applications, which can connect to your enterprise apps.
-
Make typical CRUD applications.
-
Registration, Dashboard type of applications.
-
Lightweight gaming and interaction websites.
-
Run in browser, with very small installation needed.
Coming Up:
UI Atoms from NeuroSpeech, a set of controls to develop rapid business applications on both WPF as well as Silverlight. A true alternative for DataForm on Silverlight and WPF, to have unified coding for Business Apps. Please click here to check the preview.
