WCF-All you need to know
WCF is a group of technologies that makes the communication among application(s) a real cake walk.
The Nice Part…it’s all about A…..B……C…..
check out the details here
Hope this link serves as an excellent resource for beginners and for experienced in need of quick review.
Till Next we connect………
Happy Learning!
WPF –ElementHost
In response to WPF overview-Part-I, one of my friends and a .Net enthusiast herself, requested for details on ElementHost Class of WPF (this class gave her nightmares in not getting the Children attached to it).
This might be true for many other developers who are specialized in Web Applications and have lesser exposure to windows development. As a breather to all those folks, I am here exploring this class with sincere hopes that it will provide a good insight to the class.
ElementHost as described in MSDN is “a Windows Forms control that can be used to host a Windows Presentation Foundation (WPF) element” is located under System.Windows.Forms.Integration namespace.
The members of this class have details available at this location.
Why is this Class used?
ElementHost control is used to place a WPF UIElement on to the Windows Forms control or form. In simple words, if a developer is using the traditional Windows forms and intends to use WPF controls, this control (class) is used to host them.
Likewise, while using WPF if the need is to use some Windows controls, the WindowsFormsHost element is available.
An example would be nice here, however better would be a walkthrough that is available here.
Hope this was useful,
Till Next we connect……………….
Happy Coding.
WPF Overview-Part-III
This post is in continuation to the last post.
In this Post I’ll be exploring the Following two topics
Routed Events
Data Binding
Routed Events has been covered in this post
Hence this post would be covering the details of DataBinding in WPF.
I definitely wanted to write about this topic, However it’s always good not to “RE-Invent ” the wheel every single time it is required.
So let me provide an excellent resource here that covers all possible aspects of the Binding in WPF.
This series seems to be ending abruptly and my apologies if you felt this way, but I bet after reading the above link you’ll excuse me for this.
Hope this was helpful.
Till next we connect……
Happy Learning.
WPF Overview-Part-II
This post is in continuation to the last post.
In this Post I’ll be exploring the Dependency Properties
Dependency properties are similar to CLR properties with more advanced and complex features. The main difference between the CLR properties and dependency properties is, that the value of a normal .NET property is read directly from a private member in your class, whereas the value of a DependencyProperty is resolved dynamically when calling the GetValue() method that is inherited from DependencyObject. In case this description did not make sense, no need to worry, It will become clear by the time you reach end of this article.
How the Value is Resolved in Dependency properties
Every time a dependency property is accessed, it internally resolves the value by following the precedence from high to low. It checks if a local value is available, if not, check if a custom style trigger is active and I the similar manner continues until it finds a value. At last the default value is always available.
The Following Figure depicts this searching.
Each WPF control registers a set of DependencyProperties to the static DependencyProperty class. Each of them consists of a key – that must be unique per type – and a metadata that contain callbacks and a default value.
All types that want to use DependencyProperties must derive from DependencyObject. This base class defines a key, value dictionary that contains local values of dependency properties. The key of an entry is the key defined with the dependency property.
When a dependency property is accessed over its .NET property wrapper, it internally calls GetValue (DependencyProperty) to access the value.
This method resolves the value by using a value resolution strategy described here. If a local value is available, it reads it directly from the dictionary. If no value is set if goes up the logical tree and searches for an inherited value. If no value is found it takes the default value defined in the property metadata
How to create a DependencyProperty
To create a DependencyProperty, a static field of type DepdencyProperty is added to the type (that is being created) and DependencyProperty. Register() is called to create an instance of a dependency property.
Naming Convention: The name of the DependendyProperty must always end with Property.
Dependency property can be accessed as a normal .net property by adding a property wrapper. This wrapper internally gets and sets the value by using the GetValue () and SetValue () Methods inherited from DependencyObject and passing the DependencyProperty as key.
Important: No logic should be added to these properties, because they are only called when the property is set from code. If the property is set from XAML, the SetValue () method is called directly.
Let us consider creating a dependency property in a control named WPFClockControl, giving the Current Time.
// Dependency Property
public static readonly DependencyProperty CurrentTimeProperty =
DependencyProperty. Register ( “CurrentTime”, typeof(DateTime),
typeof(MyClockControl), new FrameworkPropertyMetadata(DateTime.Now));
Now the following code creates the wrapper.
// .NET Property wrapper
public DateTime CurrentTime
{
get { return (DateTime)GetValue(CurrentTimeProperty); }
set { SetValue(CurrentTimeProperty, value); }
}
Why Use Dependency properties:
Each DependencyProperty provides callbacks for change notification, value coercion (The coerce callback allows to adjust the value if its value is lies outside the boundaries without throwing an exception) and validation (if the set value is valid). These callbacks are registered on the dependency property. In simple words, triggers (as above) can’t be set on normal .NET properties.
Readonly DependencyProperties
Creating a read only property is similar to creating a regular DependencyProperty. Instead of calling DependencyProperty. Register(),call to DependencyProperty.RegisterReadonly() is made.
This returns a DependencyPropertyKey. This key should be stored in a private or protected static readonly field of the class. The key gives the access to set the value from within the class and use it like a normal dependency property.
Second thing to do is registering a public dependency property that is assigned to DependencyPropertyKey.DependencyProperty. This property is the readonly property that can be accessed from external.
// Register the private key to set the value
private static readonly DependencyPropertyKey IsMouseOutPropertyKey =
DependencyProperty.RegisterReadOnly(“IsMouseOut”,
typeof(bool), typeof(MyClass),
new FrameworkPropertyMetadata(false));
// Register the public property to get the value
public static readonly DependencyProperty IsMouseOutProperty =
IsMouseOutPropertyKey.DependencyProperty;
// .NET Property wrapper
public int IsMouseOut
{
get { return (bool)GetValue(IsMouseOutProperty); }
private set { SetValue(IsMouseOutPropertyKey, value); }
}
Attached Properties
Attached properties are a special kind of DependencyProperties. They allow a value to be attached to an object that does not know anything about this value. Attached property does not have the conventional property “wrapper”.
More details about the Attached properties can be found here
Next article in the series will explore the remaining topics mentioned in the first article.
Hope this was helpful.
Till Next we Connect……………….
Happy Learning.
WPF Overview-Part-I
Windows presentation foundation (WPF) presents a unique paradigm that enables designers and developers to work independently and later on merge the work. This is facilitated by XAML (read more about XAML here) and the usual code behind file. WPF has a separate architecture (details here), that needs to be understood before diving into the fancy terms like dependency properties, Bindings etc.
Let us start with a quick review of Architecture.PresentationCore and Presentation Framework is the two main components that do most of the work in WPF. The Diagram below, depicts the complete architecture(This has been taken from MSDN)
There are three dlls which makes the Windows Presentation Foundation, that is WindowsBase (WindowsBase.dll), PresentationCore (PresentationCore.dll), and PresentationFoundation (PresentationFoundation.dll).
First WPF component is milcore. MIL stands for Media Integration Layer. MIL is interface between DirectX and CLR (plus above layer). MILCORE is unmanaged component which handles the 2D, 3D , Animation with the help of DirectX. WPF uses MILCORE for rendering purpose. MILCORE is also known as composition engine.
WindowsBase defines most of the Base type which are used in WPF. Hence for any WPF Application, WindowsBase library is must be a part of the solution. Second component is PresentationCore (PresentationCore.dll). This DLL doesn’t hold any UI component but it contains the base types which can be used in implementing the UI component .
PresentationFoundation contains all the WPF controls and manages other useful WPF functionality. This provides the presentation on the screen.
After architecture, following are the concepts that need to be understood for getting a good grasp of WPF
- Layout System
- Dependency Properties
- Routed Events
- Data Binding
Layout System
These are the five most popular layout panels of WPF:
| Grid Panel | The grid is a layout panel that arranges its child controls in a tabular structure of rows and columns. Its functionality is similar to the HTML table but more flexible. A cell can contain multiple controls; they can span over multiple cells and even overlap themselves.
The resize behavior of the controls is defined by the HorizontalAlignment and VerticalAlignment properties who define the anchors. The distance between the anchor and the grid line is specified by the margin of the control |
| Stack Panel | The StackPanel in WPF is a simple and useful layout panel. It stacks its child elements below or beside each other, depending on its orientation. This is very useful to create any kinds of lists
<StackPanel> <TextBlock Margin=”10″ FontSize=”20″>How do you like your coffee?</TextBlock> <Button Margin=”10″>Black</Button> <Button Margin=”10″>With milk</Button> <Button Margin=”10″>Latte</Button> <Button Margin=”10″>Cappuccino</Button> </StackPanel> |
| Dock Panel | The dock panel is a layout panel, that provides an easy docking of elements to the left, right, top, bottom or center of the panel. The dock side of an element is defined by the attached property DockPanel.Dock. To dock an element to the center of the panel, it must be the last child of the panel and the LastChildFill property must be set to true
<DockPanel LastChildFill="True"> <Button Content="Dock=Top" DockPanel.Dock="Top"/> <Button Content="Dock=Bottom" DockPanel.Dock="Bottom"/> <Button Content="Dock=Left"/> <Button Content="Dock=Right" DockPanel.Dock="Right"/> <Button Content="LastChildFill=True"/> </DockPanel>
|
| Wrap Panel | The wrap panel is similar to the stackPanel but it does not just stack all child elements to one row, it wraps them to new lines if no space is left. The Orientation can be set to Horizontal or Vertical.
The WrapPanel can be used to arrange tabs of a tab control, menu items in a toolbar or items in an Windows Explorer like list <WrapPanel Orientation="Horizontal"> <Button Content="Button" /> <Button Content="Button" /> <Button Content="Button" /> <Button Content="Button" /> <Button Content="Button" /> </WrapPanel>
|
| Canvas Panel | The Canvas is the most basic layout panel in WPF. Its child elements are positioned by explicit coordinates. The coordinates can be specified relative to any side of the panel using the Canvas.Left, Canvas.Top, Canvas.Bottom and Canvas.Right attached properties.
The panel is typically used to group 2D graphic elements together and not to layout user interface elements. This is important because specifying absolute coordinates brings you in trouble when you begin to resize, scale or localize your application. <Canvas> <Rectangle Canvas.Left="40" Canvas.Top="31" Width="63" Height="41" Fill="Blue" /> <Ellipse Canvas.Left="130" Canvas.Top="79" Width="58" Height="58" Fill="Blue" /> <Path Canvas.Left="61" Canvas.Top="28" Width="133" Height="98" Fill="Blue" Stretch="Fill" Data="M61,125 L193,28"/> </Canvas>
|
As found in most of the cases in my blogs, I prefer digesting the newly acquired knowledge, so take some time and explore the Architecture and Layout. The remaining topics would be covered in the upcoming Post.
Till Next we connect…….
Happy Learning!
WPF Routing
WPF (3.5) introduced the concept of Routing that made the event routing easies in the scenarios where it was tedious to handle events. Consider a scenario where there are a number of Hyperlinks in a Panel that direct to separate locations on Click. Now if this is done in normal programming, each hyperlink will have to have code for execution. It would be easier and cleaner if we could handle the hyperlinks in the container (the Panel) that handles the click and redirects to appropriate location.
WPF handles the events with the following 3 strategies.
- Direct events are like ordinary .NET events. They originate in one element and don’t pass to any other. For example, MouseEnter is a direct event.
- Bubbling events are events that travel up the containment hierarchy. For example, MouseDown is a bubbling event. It is raised first by the element that is clicked. Next, it is raised by that element’s parent, and then by that element’s parent, and so on, until WPF reaches the top of the element tree.
- Tunneling events are events that travel down the containment hierarchy. They give you the chance to preview (and possible stop) an event before it reaches the appropriate control. For example, PreviewKeyDown allows you to intercept a key press, first at the window level, and then in increasingly more specific containers until you reach the element that had focus when the key was pressed.
RoutedEventArgs Class:
- Source indicates what object raised the event.
- OriginalSource indicates what object originally raised the event. Usually the OriginalSource is the same the Source. But in some cases they could be different. For example, if you click close to the border of a window, you will get a Window object for the Source but a Border object for the OriginalSource.
- RoutedEvent provides the RoutedEvent object for the event triggered by your event handler.
- Handled allows you to halt the event bubbling or tunneling process.
Here is a simple example of when you might use a bubbling event:
<StackPanel Hyperlink.Click=”StackPanel_Click”>
<TextBlock>
<Hyperlink NavigateUri=”http://www.google.com”>Google</Hyperlink>
</TextBlock>
<TextBlock>
<Hyperlink NavigateUri=http://gmail.com>Gmail</Hyperlink>
</TextBlock>
<TextBlock>
<Hyperlink NavigateUri=http://facebook.com>FaceBook</Hyperlink>
</TextBlock>
</StackPanel>
And to handle the HyperLinks..
private void StackPanel_Click(object sender, RoutedEventArgs e)
{
Process.Start(((Hyperlink)e.Source).NavigateUri.ToString());
}
So instead of having to create an event handler for each hyperlink, or creating a single event handler and pointing each hyperlink to the same event handler, one event handler on the parent element can be used.
This article just covered the Routing Basics and can serve as a base material to get started, However there is still lot that needs to be learnt and the who else, other than MSDN can teach it better.
Hope this was helpful,
Till Next we Connect…….
Happy Learning.
The Source Code can be downloaded from here
Application Design Diagramming Techniques-Part-III
Sequence Diagram
Sequence diagram shows object interaction during execution (or run time). The model demonstrates the lifetime of these objects and shows the message exchange between them.
The UML notations are critical in sequence diagrams.
Objects are listed as rectangles at the top of the diagram with lifelines extending from them.
An object lifeline is an indication of how long an object will live before it is disposed of or made ready for garbage collection. The objects themselves are described in the rectangle that sits atop this lifeline. The description that goes in the rectangle is meant to describe an instance of the class. Description is written as an Object or the Object, where the object is the name of the class or variable representing the class.
The long rectangles that extend along the lifeline of each object indicate when an object is created and when it goes out of scope.
The messages that pass between objects are indicated by the arrows from one lifeline to another. These messages are meant to be read from top to bottom and left to right (as a sequence). Each message represents a method call, property call, or return value.
Return calls are shown as a dashed arrow
Asynchronous messages are demonstrated by using an arrow that has only its lower half.
The Following Diagram depicts the theory covered above.
Here, we have 4 objects EditUser, User, UserService and a database.
The GUI contains Edit User functionality and the internal processing done when editing user is shown above.
Following are some other links that can be used as reference.
Hope this was useful…..
Till Next we connect…..
Happy Learning
Application Design Diagramming Techniques-Part-II
component diagrams
A component diagram is used to indicate the components (or code packages) that will be created for the application. A component is made up of logically related classes grouped together in a single deployable unit (consider them the DLLs or Web services).
The components are represented by the rectangles that include the two smaller rectangles on their left, as depicted below.
Each component name is preceded with text, indicating its logical layer, and then two colons. This text represents the components package.
The outer boxes that surround the components are called nodes.
All this is demonstrated in the figure below.
Class Diagrams is another diagram that can be created easily using Visual Studio and id the most commonly used diagram and would not be covered here.
Next post will cover Sequence Diagram.
Till next we connect……
Happy Learning.
Application Design Diagramming Techniques-Part-I
This and few other subsequent posts will explore the diagrams used in designing the application in developing the Logical model for application.
This post explores the ORM(Object Role Modelling)
Object Role Modeling (ORM):
An ORM diagram includes the primary objects (also called entities) in the system, the relationships between those objects, and the attributes (and even attribute values) that define those objects. ORM notation is used to create this logical representation between objects.
ORM Objects
In ORM diagrams, each object is represented by an oval containing the name of that object.
Simple rule to identify ORM objects: Any nouns in the requirements or use case is an ORM object
ORM Relationship
An ORM relationship defines how two or more objects are related to one another. In an ORM, a relationship between objects is represented as a line connecting the objects. Along this line will be a rectangle divided into segments based on the number of objects in the relationship. This is typically two segments because most often, you are modeling relationships between two objects (called a binary relationship). However, if you are modeling a relationship that exists among three objects (called a ternary relationship); all three relationships need to be defined
Project and developer has a binary relationship. A developer can be assigned to a Project.
Ternary relationship exists between Release, manager and developer. A release consists of efforts from developer(s) and manager.
ORM Facts
A fact indicates how two (or more) items are related. This is also called the fact model for the application. They represent how objects really relate to one another.
The Facts depicted in figure can be read as;
A project has developer and in reverse Developer is in Project
For Ternary relation Developer and Project manager makes a release and reversely a Release has a manager and developer(s).
Similarly, a Manager has Employee details and Employee Details is of manager.
An employee detail has a Name, EmployeeID and Designation and Designation, EmployeeID and Name is of Employee details (that is a manager).
ORM Constraints
ORM constraints define how the objects participate in the relationship. This includes defining which objects are mandatory and the multiplicity of the relationship. Mandatory objects in a relationship are indicated by a closed (or filled) circle attached to either end of the connection. This closed circle indicates that the given object is mandatory in the relationship. That is, the related object does not exist without this object.
Multiplicity indicates whether two objects relate to one another as one-to-one, one-to-many, or many-to-many. Multiplicity is indicated with a series of arrows over the relationship shape.
In the Above figures, the objects are mandatory; however No Color has been used for Filling.
The Figure below depicts the Multiplicity notation(s).
Try to put these constraints in the Figure-1 or Figure-2 to get the complete picture of ORM diagram. This has been left intentionally as a practice to the reader.
Note: ORM diagrams, as a myth are thought to be used in Database diagramming only, however it serves as an excellent tool for initial designing phase(s).
The next few post will cover the other diagramming techniques that include component diagram, class diagram, activity diagram, Sequence diagram, collaboration diagrams.
Hope this article was helpful….
Till Next we connect…….
Happy Learning.

Try to put these constraints in the Figure-1 or Figure-2 to get the complete picture of ORM diagram. This has been left intentionally as a practice to the reader.
Note: ORM diagrams, as a myth are thought to be used in Database diagramming only, however it serves as an excellent tool for initial designing phase(s).
The next few post will cover the other diagramming techniques that include component diagram, class diagram, activity diagram, Sequence diagram, collaboration diagrams.
Hope this article was helpful….
Till Next we connect…….
Happy Learning.
Application Designing-Requirements to Prototypes
Application design is one of the most critical part of software design..it it’s right the road ahead is a cakewalk…if not…Nightmare begins.
Here I am starting a series of posts that will explore the application design processes and tools in detail
Prior to application design, Requirement gathering constitutes the basic framework on which design is built. The requirements need to be analyzed from 4 perspectives to make valid requirements docs. The figure below sums up these perspectives
Here QoS is Quality of Service that also needs to be considered.
Use cases also are a means of defining the requirements and sometimes serve as the main basis for application design; however there are some basic differences.
Use Cases versus Requirements
A use case is a Unified Modeling Language (UML) model meant to describe a set of user steps that accomplish a task.
Requirements define what must be created to satisfy the needs of the user. Together, they provide a good view of how the user sees the system.
One the requirements are finalized, the Prototype validates the requirements that can be a POC or Mockups.
Mockups and Proof-of-Concept Prototypes
A mockup is meant to verify the requirements and use cases through the creation of a number of key screens in the system. Mockups are also called horizontal prototypes because they take a single, horizontal picture of the application. They do not go deeply (or vertically) into the other layers of the application such as the business objects and the database layers. Mockups are a great way to determine whether the requirements are complete and understood. They also help validate the use cases, the navigational structure, and some of the logical interactions of the application.
Mockups shortcomings
They do not help to prove any of the architecture concepts for the system. They also do not validate the technology decisions.
Mockups Advantages:
Mockups are useful for defining how the application will look and behave. This removes ambiguity from the implementation and builds early consensus on what will be delivered.
A proof-of-concept prototype is meant to validate the requirements and confirm the technology recommendations and high-level design. A proof-of-concept prototype is also called a vertical prototype because it looks at the application across the entire stack (UI, services, business objects, and database). Proof-of-concept prototypes have also been called reference architectures because they provide a reference for the development team on just how the system should work from top to bottom. This removes ambiguity, creates a standard, and eliminates a lot of risk.
Proof-of-concept prototype is generally, created by choosing a key requirement of the application and then building it out through each layer of the design. It makes more sense to prove out a riskier requirement than to work with a well-known requirement.
After going through the above exercises, the main work of design begins, as summarized below.
As the above figure depicts the first design phase is to develop Logical Model. All these designing phases make use of certain diagramming techniques ranging from ORM diagrams to Sequence and collaboration Diagrams.
These Diagrams will be covered in next post, which will explain all the used diagrams in detail.
Hope this was helpful..
Till Next we Connect….
Happy Learning.
-
Archives
- January 2011 (11)
- December 2010 (4)
- November 2010 (1)
- July 2010 (1)
- June 2010 (1)
- May 2010 (3)
- March 2010 (3)
- February 2010 (10)
- January 2010 (4)
- September 2009 (1)
-
Categories
-
RSS
Entries RSS
Comments RSS









