BAML vs XAML

XAML(eXtensible Application Markup Language) is an XML-based language, through which a developer can create rich UI easily and much more rapidly for WPF or Silverlight applications.
Anything that can be done in XAML can also be done in codebehind.
When we compile our WPF application in Visual studio, it compiles the XAML files into a compressed format called BAML (Binary Application Markup Language) and saves it to the assembly as resources with .BAML extension. On calling InitializeComponent() from WPF constructor, it will load the BAML file from assembly and create the object.

Continue reading

Some Advanced Controls in WPF

In the previous tutorials, we have learnt about basic controls, their positioning and their placement within panel controls. In this tutorial, we are going to tackle some slightly advanced controls and their usage. These controls, in conjunction with panels and other classes, aid in advanced and intelligent layout creation. Some commonly used slightly advanced controls include TabControl, GroupBox, Menu and Expander. We are going to study each of these in further detail now.

Continue reading

Commonly used Panels in WPF

In the previous tutorial, we learnt how to create a simple application using the DockPanel. In this tutorial, we will learn about application layouts and the support that WPF provides to arrange controls in a good layout using different types of panel controls. So far, we have learnt about creating basic WPF programs, adding controls and properties. We also already know about simple controls like buttons and textboxes. Remember, a control is something that derives from System.Windows.Controls.Control base class. Most elements that you come across in a WPF UI are controls. The base class in turn derives from System.Windows.FrameworkElement base class, which provides them with framework-level set of properties, events, and methods. The properties help in fine-tuning their positioning and appearance. For example, margin and horizontal/vertical alignment are some properties.

But haphazardly arranging the controls is not going to lead to a good application no matter how correctly or intelligently you add the controls or how much you attempt to control their positioning. Fortunately, as we learnt in tutorial 1, WPF has built-in intelligent layout capabilities to arrange the visual elements of an application. Before beginning to experiment further with the intelligent layout capabilities of WPF, it is important to understand about panel controls that play a large part in helping you arrange other controls efficiently. We will now learn about different panel controls and see the usage of some of the most commonly used panels.

Continue reading

Using Hierarchical Data templates

As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls for several of my UI requirements and find that they are quite easy to use once you get the hang of it. However, the controls can seem a little confusing and hard to use for a beginner, especially if you have a background only in winforms. It is much easier if you try to work with individual controls and understand their behavior in the beginning stages.
Continue reading

FontViewer

In the previous tutorials, we learnt how to create a WPF application using visual studio templates, and we also learnt how to use some basic controls and set their properties. Now, let us make a cool FontViewer program as the next step. This program is taken from Sams Teach Yourself WPF in 24 Hours book – an excellent resource for beginners to WPF.

Continue reading

Setting Complex Properties in WPF

In the last tutorial, we learnt how to create a simple WPF application using visual studio, how to add controls to the XAML and how to set properties to them (remember height and width of button?). The properties we set in the tutorial were, however, of simple value type. Not all properties are of simple value types. Some properties are made up of multiple objects, which might themselves have multiple properties, which might again have objects…you get the idea! These are complex type properties and setting them is slightly more complex too.

Let us consider the case of “Background” property on the Button control.

Continue reading

Getting Started with XAML

You should now have a basic understanding of what WPF is and when and why you should use it. Now come the components of WPF. The first thing you should understand, when developing WPF applications is XAML. XAML is the core of WPF applications (also of silverlight, but more of that later).

XAML stands for Extensible Application Markup Language. You pronounce it as “zamel”. It is an XML based language used for creating user interfaces in WPF + for serializing .NET object instances into a human readable format. It is also used by the workflow foundation for defining workflows but that is beyond the scope of this tutorial. The main advantage that XAML provides is declarative UI. You can create UI elements in the xaml, and then separate the visual aspect from logic by putting the logic in code-behind files (xaml.cs), joined to xaml through partial class definitions.

Continue reading

Introduction to WPF

This post is first among a series of tutorial posts that will teach WPF to beginners. The entire series will be divided into around 20-25 posts and each one should take you around 1/2 to 1 hour maximum to read and understand. If you follow them in the order that they have been written (from bottom to top), the series will not take more than a few days to complete. However, it is expected that you will have some basic background of .Net development and understanding of .Net framework before you begin these. If not, look forward to our next tutorial series on .Net development. All the code in these tutorials are written using Visual Studio 2012, and for database, we are going to use MS SQL 2008 R2. The code will work even on older versions of Visual Studio (those that support WPF) but you may have to change some things manually, and since it is not possible to list all the changes, we recommend using 2012 for a seamless learning experience. The express edition is free for trial.

Continue reading