Posts

Showing posts from May, 2014

WPF XAML, Loose XAML and BAML Files: Approaches to create WPF applications with XAML

WPF XAML, Loose XAML and BAML Files: Approaches to create WPF applications with XAML There are four approaches to create WPF application with XAML. You can use XAML directly to in WPF application or can convert XAML into the BAML for improving its performance or you can use loose XAML or do not use XAML at all. Lets try to understand these approaches of creating WPF applications with XAML. Code and compiled markup(BAML): This is the preferred approach for WPF applications. This approach is used by Visual Studio. You can create XAML template for each window, and this XAML is compiled into BAML and embedded in a final assembly. At runtime, the compiled BAML is extracted and is used to generate the user interface. Code and uncompiled markup(XAML): You can use this approach when you are creating highly dynamic user interface. In this approach, you load the user interface from a XAML file at runtime using the XamlReader class from the System.Windows.Markup namespace. Code only: This is t

WPF Layout Controls/Containers, Layout Process, Properties and Tips

WPF Layout Controls/Containers, Layout Process, Properties and Tips All the WPF Layout containers are panels that derive from the abstract System.Windows.Controls.Panel class. Mainly, there are five layout containers in WPF: 1. StackPanel 2. WrapPanel 3. DockPanel 4. Grid 5. Canvas I am not going to explain working of all these panels as it is already very well explained here . I will add some extra details about these layout controls in WPF. I will go through WPF Layout Process Stages ( Measure Stage and Arrange Stage ), how can we create our custom layout containers using MeasureOverride() and ArrangeOverride() methods, different WPF layout properties and some tip and noteworthy points about WPF layout containers. WPF Layout Process WPF Layout takes place in two stages: A) Measure Stage: The container loops through its child elements and asks them to provide their preferred size. B) Arrange Stage: The container places the child elements in the appropriate position. Creating WPF C

WPF XAML and BAML: XAML Introduction, Advantages and Compilation

WPF XAML and BAML: XAML Introduction, Advantages and Compilation This article on WPF XAML covers basic concepts of XAML, Advantages of using XAML into WPF, how XAML elements are related with .NET classes and how XAML in actually compiled in WPF applications. We will get an idea on how WPF XAML code is converted into the BAML and again how BAML code is converted into the XAML and the role of InitializeComponent() method in the process. XAML stands for Extensible Application Markup Language and is mainly used to create WPF user interface. XAML is also used in Silverlight and WF (Windows Workflow Foundation). You can create XAML using Visual Studio as well as Expression Blend. Basically Visual Studio is for developers and Expression Blend is for designers. Advantage of XAML in WPF applications In WPF, due to the introduction of XAML, graphical designer can separately work on user interface and developers can concentrate on the main logic. But it was not possible in Windows Form because an

WPF Introduction, Architecture and Core Classes

Image
WPF Introduction, Architecture and Core Classes WPF is a modern graphical display system for Windows. WPF has innovative features like built-in Hardware Acceleration and Resolution Independence.  Before WPF, User32 and GDI/GDI+ components were used for creating user interface which had a lot of limitations. Windows Forms and VB6 used these User32 and GDI/GDI+ components for creating user interface. To overcome limitations of User32 and GDI/GDI+, DirectX was introduced. DirectX is the highly efficient toolkit of game development on Windows and has support for all modern video cards. WPF uses DirectX instead of GDI/GDI+. User32 is still used but its use by WPF is very limited. WPF 4.5 is compatible only with Windows Vista, Windows 7 and Windows 8. For Windows XP, you will have to configure Visual Studio to target .NET 4.0 framework rather than .NET 4.5. WPF Architecture WPF Architecture can be divided into three layers: 1. Managed WPF API Layer includes A) PresentationFramework.dll: Su

WPF StaticResource and DynamicResource Examples and Explanations

WPF StaticResource and DynamicResource Examples and Explanations A WPF Resource is an object that can be reused in different places in your WPF application. Brushes and Styles are the best examples of WPF Resources. WPF Resources are not the part of visual tree but can be used in your user interface. Generally WPF objects are defined as resources, which are used by multiple elements of the application. WPF Resources are of two types: 1. Static Resource 2. Dynamic Resource 1. StaticResource: StaticResources are resolved at compile time. Use StaticResources when it's clear that you don't need your resource re-evaluated when fetching it static resources perform better than dynamic resources. Syntax for StaticResource usage:  <object property="{StaticResource key}" .../>  2. DynamicResource: DynamicResources are resolved at runtime. Use DynamicResources when the value of the resource could change during the lifetime of the application. Syntax for DynamicResource u

Usage of ObservableCollection class and INotifyCollectionChanged interface in WPF Data Binding

Usage of ObservableCollection class and INotifyCollectionChanged interface in WPF Data Binding The ObservableCollection<T> is one of the most important features of WPF data binding. ObservableCollection is a generic dynamic data collection that provides notifications (using an interface "INotifyCollectionChanged") when items get added, removed, or when the whole collection is refreshed. Namespace for ObservableCollection: System.Collections.ObjectModel Syntax for ObservableCollection: [SerializableAttribute] public class ObservableCollection<T> : Collection<T>,  INotifyCollectionChanged, INotifyPropertyChanged ObservableCollection has a lot of properties, methods, events, explicit interface implementations. Get a complete list on MSDN . Main feature of the ObservableCollection<T> are the events it raises when the items it contains change. When in your WPF application, you make any changes like remove/add/edit item in the ObservableCollection, the Ob

Basics of WPF ICommand Interface in MVVM

Basics of WPF  ICommand Interface in MVVM I am going to cover basics of ICommand interface in WPF in MVVM pattern like syntax of ICommand interface, methods and events of ICommand interface, how to bind ICommand in View(XAML), how to implement ICommand interface in ViewModel etc.  1. Namespace for ICommand System.Windows.Input Assembly: System System.Windows.Input supports many Classes, Structures, Interfaces, Delegates and Enumerations. Here is the complete list on MSDN . 2. Methods exposed by ICommand A) CanExecute: Defines the method that determines whether the command can execute in its current state. Typically, a command source calls the CanExecute method when the CanExecuteChanged event is raised. Syntax: bool CanExecute(Object parameter) Parameter: System.Object Return Value: Boolean B) Execute: Defines the method to be called when the command is invoked. Syntax: void Execute(Object parameter) Parameter: System.Object 3. Events exposed by ICommand A) CanExecuteChanged: O

DataBinding in WPF using DataContext in XAML

DataBinding in WPF using DataContext in XAML I would like to share a very simple example of databinding in WPF using DataContext in XAML file. In this WPF databinding simple example, I have a class named EmpViewModel which has two properties EmpID and EmpName. I will bind these EmpID and EmpName properties with two textboxes in the XAML file. Following is my EmpViewModel class under SampleApplication namespace: EmpViewModel.cs namespace SampleApplication {      public class EmpViewModel     {         private int empID;         public int EmpID         {             get             {                 return 123;             }             set             {                 empID = value;             }         }                  private string empName;         public string EmpName         {             get             {                 return "ABC";             }             set             {                 empName = value;             }         }     } } After this class, I h

Delphi Coding Standards and Guidelines

Delphi Coding Standards and Guidelines Below are some Delphi coding standards and guidelines mentioned which each Delphi developer should take care of. Anybody can code, but neat and clean coding is an art. I have tried to mention some Delphi coding standards and guidelines which I follow everyday. Following list includes use of proper naming convention and indentation, proper exception handling and resource management, usage of proper datatypes etc. 1. Use proper naming convention Use proper naming conventions and provide meaningful names to classes, records, arrays, enumerated types, pointers and other variables so that code readability is maintained and other developers can easily understand your code. 2. Always maintain a clear indentation Always leave two character spaces before writing the child statement. Here is the example. if condition1 then begin     fist statement     second statement end; 3. Declare records/class names prefixed with 'T' character, pointer names pre

How to Insert/Edit Rows in Firebird Dataset in Delphi using FIBPLUS Components?

How to Insert/Edit Rows in Firebird Dataset in Delphi using FIBPLUS Components? You can insert a row and edit an existing row in firebird dataset in Delphi. I will use FIBPLUS dataset component in Delphi XE4. Just use Insert and Edit procedures for this purpose. First of all create a dataset of type TpFIBDataset. Lets have a look at this very simple example. var dsMyFirebirdDataset : TpFIBDataset; Insert a row in a dataset with dsMyFirebirdDataset do begin Insert; dsMyFirebirdDatasetID.AsInteger := 101; dsMyFirebirdDatasetDESC.AsString := 'Hello'; Post; end; You can also use FieldByName like following: with dsMyFirebirdDataset do begin Insert; FieldByName('ID').AsInteger := 101; FieldByName('DESC').AsString := 'Hello'; Post; end; Similarly, you can edit a record/row in the dataset like following: Edit a row in a dataset With dsMyFirebirdDataset do begin Edit; dsHdwPriceGroupDESC.AsString := 'Hello World'; Post; end; or With