Binding literally means a link or connection between two objects. In WinForms world, binding usually meant fetching data from a database, filling up the DataSet objects and then binding them with the data grid on the visual layer. Although there was the possibility of binding the UI layer to custom business objects – there was little support from the framework to achieve this. We can’t say it was totally absent, because the interface we use in .NET 3.5/4.0 for binding – INotifyPropertyChanged (in System.ComponentModel namespace) has been available since .NET framework 2.0.

Binding in real world:

Let us begin with wiping out WinForms from our minds. If we want to develop a banking application with the UI given above, what comes to your mind? With our background in OOPS we would start thinking in objects (or if you are designer you would start with selecting a better color for the text :-). Objects we think are a Customer with all properties like name, account no., balance etc.; a Bank object with bank name, a web service to fetch/update customer details.

Sunday, 25 September 2011

Problem: I am building a dash-board kind of application. Idea is we have a main window displaying various buttons which represent a ‘module’. On clicking these buttons we show a separate window. Now these ‘module’ windows can be closed, but if we invoke them again from the dash-board window we should re-use the Window object.To solve the problem of showing the same Window object each time it is invoked we save the Window object in a list, and override the Close behavior.Solution: We create custom Window class and override the Closing method, so that Close is not called and we could reuse this object.Implementation:1> Create a custom class, let’s name it WindowBase.Add the namespace “System.Windows”, inherit the class from Window:

Since we want to change the Closing behavior we override the OnClosing() method and set the e.Cancel = true.
Now we will use WindowBase class to create all the “module” windows.

2> Create a new Window using WindowBase class.

We add a new Window to the project, by right-clicking project and selecting Window.
By default we will get the following XAML code in the newly added Window:

<Windowx:Class="InheritWindow.Window1"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

Title="Window1"Height="300"Width="300">

<Grid>

</Grid>

</Window>

Now since we are going to use a new class we need to define its namespace so that XAML can understand it.
So we:
> add: xmlns:w="clr-namespace:InheritWindow"
> replace “Window” with “w:WindowBase”
> remove the inheritance from “Window1” class defined in in Window1.xaml.cs (We could change this to WindowBase but it is not necessary, as the inheritance hierarchy is set by XAML, where we are using <w:WindowBase>.)

We are using the WixUI_Mondo in our setup so that we could allow the users to select/de-select features. However the app is installed on intranets so we did not want to show the License Agreement dialog box. A few pp. suggested downloading the Wix source code and manually changing the part which shows up the LA dialog box.

I found out that we could also, change the click event action of Next and Back button controls using Publish tag.

So we changed the Next button click event action of the ‘Welcome dialog’ (WelcomeDlg) to show directly the second dialog box. For .e.g: