UI Atoms 2010 v1.9 update now includes Trace API for developers to log information on screen just like normal .NET application.
Diagnostics Trace API
Microsoft .NET provided Trace API to help in troubleshoot problems which is of great help at time of development. But Silverlight developers are disappointed for not being able to trace in Silverlight apps. However running apps on multiple platform isn’t quite easy, and different user experiences on different platforms raise unexpected issues. Such issues are difficult to resolve as deployed client computer may not have development tools available to troubleshoot and see application logs.
Trace.WriteLine(“ Hello World “);
We sure miss Trace in Silverlight, so we decided to add similar diagnostics API in Silverlight.
Trace Viewer
In Silverlight, as it runs inside a browser, there is no way to see any trace information not only this, on different platforms like Mac, it may be too difficult for no technical user to install and enable remote debugging.
So we decided to include a visual component that can be put anywhere on screen, just like “Output” pane in visual studio. Its developer’s choice to fit the Trace Viewer. Its pretty simple Text View control, where in you can see lines of log automatically scrolling down as log grows.
AtomTraceView
UI Atoms’s AtomTraceView control works well with Silverlight as well as WPF, in WPF it uses inbuilt Trace functionality and displays trace information to user, and in Silverlight we have added custom API, that is used to display Trace information. Syntax is pretty simple.
<Grid> <Grid.RowDefintions> <RowDefinition/> <RowDefinition Height="200"/> <Grid.RowDefintions> <MyUserControl/> <AtomTraceView Grid.Row="1"/> <Grid>
This way you can include AtomTraceView at the bottom of your page and it will display all traces programmed by the developer.
Limited API
However, .NET Trace API is very huge, and it is extensible, but Trace API offered by UI Atoms as of now is very limited, not by the design but by implications, Silverlight itself is very limited platform, this is just an Add-on for users to troubleshoot their apps.
Trace Statements in Silverlight
In order to write Trace statements, you have to import following namespace,
using NeuroSpeech.UIAtoms.Core;
Then you can write following statements and they will appear in AtomTraceView Control.
AtomTrace.WriteLine(" Hello World "); AtomTrace.WriteLine( exception.ToString() ); AtomTrace.WriteLine( string.Format("{0},{1} Coordinates", x, y) );
The AtomTrace class exists for both Silverlight and WPF, so it becomes easier to write your logs with AtomTrace instead of Trace, so your code can be shared on both Silverlight as well as WPF.
Trace and Multithreading
Trace statements can be accessed by thread in Silverlight app, however the sequence in which it will appear can not be guaranteed because it depends upon the processor and scheduling algorithm used in thread pool of Silverlight application.
Custom Trace Listener
Just similar to .NET, we have included AtomTraceListener class, which you can derive and customize trace information according to your need as well as it has Traced event, which you can implement and get trace notifications anywhere..
Future of Trace API in Silverlight
When Trace API will be included by Microsoft in future edition of Silverlight, we may plan to remove Trace API, to be consistent with the Silverlight development workflow, this API has been enabled only to write shared code between WPF and Silverlight environment. However otherwise, we plan to make tracing more rich with UI Atoms. But for now, it is very helpful for everyone.
Live Demo
Click Here to see live demo of Tracing in Silverlight.
Click Here to download demo version of UI Atoms 2010.
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.
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.
