Sunday, April 22, 2007

WPF and Windows Forms

While learning WPF, in order to take advantage of its neat features (i.e graphics, animation etc), you will most likely want to get busy using WPF in your projects as soon as possible. You can do this even if you are not up to speed on all WPF features.

It is possible to have both WPF Windows and traditional Windows Forms within the same VS 2005 .NET Framework 3.0 Windows Application (WPF). You can use WPF forms where you feel comfortable, but use Windows Forms for other situations.

For example, suppose that you have not yet got up to speed with WPF data binding -- you could implement that in a Win Form using the traditional data binding techniques, but do other application interfaces using WPF (i.e About Form, Search Form).


In .NET code, both WPF Windows and Windows Forms are objects and can be thought of as a "form"

For example:
Dim f as SomeForm 'could be a WPF or Win Form
f.show

You can show a WPF form from a Windows Form or show a Windows Form from a WPF form.

Saturday, April 21, 2007

Some Beginning XAML

XMAL gives developers the means to customize their user interfaces in ways that have not been available using traditional tools (i.e. Windows Forms).

The following XMAL snippet gives a simple example:

<StackPanel Background="Beige">

<Button>

<Button.ToolTip>
<TextBlock FontWeight="UltraBold" TextAlignment="Center">
<Ellipse Width="20" Height="20" Stroke="Blue" Fill="AliceBlue"></Ellipse>
<Label>A ToolTip Message</Label>
<Rectangle Height="20" Width="20" Fill="AliceBlue" Stroke="Blue" StrokeThickness="2" ></Rectangle>
</TextBlock>
</Button.ToolTip>

<Button.Content>
<TextBlock FontWeight="UltraBold" TextAlignment="Center">
<Ellipse Width="20" Height="20" Stroke="Red" Fill="Pink"></Ellipse>
<Label>Press Me</Label>
<Rectangle Height="20" Width="20" Fill="Pink" Stroke="Red" StrokeThickness="2" ></Rectangle>
</TextBlock>
</Button.Content>

</Button>
</StackPanel>

The button defines its own content and a tooltip. Notice that the content and tool tip defintions can contain other XAML, allowing for very interesting presentation. Here, both the button and tool tip have tradtional text (i.e. Press Me) as well as a Rectangle and Ellipse. No longer are developers constrained by text only or creating their own images with hope that a control supports display of an image.

The other good news is that when the window with the above is resized, the button contents are automatically adjusted to ensure that it continues to have a consistent look and feel -- and the best part, a developer does not have to do anything to get this behavior!!

Thursday, April 19, 2007

I'm Back

After a long, long break from blogging, I am back!! For a while I have been using/learning Windows Presentation Foundation. I find this feature of .NET 3.0 to have huge potential for changing, enhancing the way user interfaces are designed and implemented for applications.

I have been using VS 2005 with the Visual Studio 2005 extensions for .NET Framework 3.0. concentrating on standalone applications (the traditional Windows Forms application development that we all know and love)

The good news is that I am able to leverage my knowledge of Visual Studio in order to get right to work creating .xaml to define the UI along with implementation of business intelligence code (usually in VB.NET). Actually when beginning to learn/experiment with Windows Foundation Presentation, which more then likely means being exposed to XAML (eXtensible Application Markup Language) rather quickly, keep in mind what I like to think of as ".NET/Visual Studio" patterns.

For example in a VS 2005 NET Framework 3.0 Windows Application, when adding a new WPF Window to a project results in 2 files being added to that project, one for the xaml (aName.xmal) and one for managed code (i.e aName.xaml.vb). These files are associated with one another - in the xaml file the user interface is defined using XAML, while in the.xaml.vb file holds any associated managed code.

For ASP.NET Web developers this mirrors the "code-behind" approach; user interface defined in .aspx using HTML and code in the associated .aspx.vb file. As is the case with ASP.NET, you could decide to keep code (VB or C#) along with the XAML in the same .xaml file. This is analogous to an in-line ASP.NET approach.

My point here is to keep in mind familiar concepts and patterns about .NET and Visual Studio as they will appear quite often while learning WPF. Recognizing them will help speed up the learning curve.