Forms, WPF, dotNet 4.0 and Much More ...

 Top Next

This is a HUGE topic area, and one in which there is much to embrace for GUI designers

and application developers.

The new technologies included in dotNet 4.0 and WPF generally, will make our lives as developers

both more interesting, easier, and lead us into fun things of which we have not yet even dreamed !

After my few months exploratory work with WPF and dotNet 4.0, I highly recommend that you

give the subject a 'real go' for yourself - you won't regret it.

Finally, I suggest while researching into WPF and the new stuff available in dotNet 4.0, you

actively look for places, and areas, to leave old ways and techniques behind, and thoroughly

embrace the well designed and 'thought through' new namespaces and their classes.

I hope you enjoy it as much as I have - and will in many months to come. For me, Forms

technology is a thing of the past, and WPF is the focus of the present, as well as the future.

Good Luck on the journey.

PHH - 7th. May 2010.


Overview

 Top Previous Next

Put quite simply, these session notes are designed to help any Vulcan.NET developer

get into WPF as fast as possible.

They try to eliminate the 'blind alleys' and time wasting efforts which most new guys will take and make ;-)

If the help and information is not specifically given here in the notes, then other learning sources

are pointed to for Vulcan coders wishing to gain access to the full power of WPF and dotNet 4.0

technologies.

Does this hint at advising guys (and old VOers too) to miss out Forms 2.0 and go straight to WPF

windows ? I am not sure about this - at this very moment.

It would seem like a good idea, however, I feel that any developer without a fair amount of dotNet experience will

feel the move straight into WPF as just a stride too far.

If you are familiar with dotNet, with all its various facets, then yes, 'go for it' !

However, I suggest that VOers coming to VN will need to go a little more cautiously. It would have been

far too much for me, BUT, at least the new guys coming now, have a lot of suitable material to look at,

copy, and adapt. So it may be different for them.

[ Make sure you get access to all the ClickStart volumes of eNotes. ]

ClickStart Executive

Home page - ClickStart !


The Future

Generally :

Once enough people get to hear about the 'real' benefits of WPF, and developers get into some initial

application projects, there will be no stopping things.

WPF is so much part of the Silverlight development that Forms technology will have to be left for what it is

by any company and developer wishing to keep in business, or employed.

It needs to be realised that WPF and Silverlight - the Unified Interface (UI) - is a keystone to what

Microsoft considers their .NET 'solution'.

If you think that dotNet (.NET) is just a huge bunch of classes, then think again. These are just the

'framework' to support a whole solution approach, and the UI is a large part of this. In the way that SQL

was 'Data at a Distance' then WPF and Silverlight is 'GUI at a Distance'.

Since the web, and it huge commercial impact, has made the 'at a Distance' phrase rather an important

part of this discussion, we need to embrace it all or die!

Fortunately, or unfortunately, XAML is simply a necessary single aspect of making the 'GUI at a Distance'

work. But don't let the XAML get in the way for you and your research into WPF. You can add it on gradually,

as you progress with WPF - see later sections of these notes.

However, if we are to use Silverlight and ASP.NET for web services, then we will need to add a few scripting

skills to our armoury. Once we get the bug for WPF, and see some of its real benefits, adding these

apparently quite easy to acquire skills will not be too difficult - for us with a programming background.

Personally :

I have already gone over completely to using WPF, unless I "have to" use Forms 2.0 for some reason.

To me there seems just too many benefits on offer, to not make the switch.

Having got the bug for dotNet coding with Forms, I find WPF and its supporting technologies, much more

dotNet in nature. All the things I have become to like about dotNet are there in greater perfusion in WPF.

Finally, I will continue to plumb the depths of the dotNet classes for WPF, and try to add some XAML scripting

skills if and when required. [ There will be a 'ClickStartXAML'. ]

However, I particularly look forward to the new features for graphics and images, as well as discovering the

new GUI layout techniques and controls.

Visual Studio 2010 :

It will be interesting to compare the IDE facilities available to the developer in VS2008 and the new VS2010.

My feeling using the earlier (VS 2008) WPF designer facilities, was that they were only part completed. As if

they had been left unfinished.

It is my feeling also that much more 'click and type' entry will be available through the Properties pane in the

newer version of VS.

Although the interactivity was in place for some PP entry, which also showed up in the XAML script, it was far

less than expected - after using other, more mature parts of the VS2008 environment.

Personally, I look forward to the new challenges.


Introduction to these Notes

Hi guys,

These notes came out of some exploratory work I started about Christmas time 2009.

I had not expected to have gotten as far as I have with WPF, and its deeper features and functionalities.

My progress, and successes, say something for the way Microsoft have designed and built WPF and

the new dotNet 4.0 classes. I congratulate them.

I have tried to put into a few simple sections the best parts of what I have found out in my WPF travels.

Having had my enthusiasm 'dented' by XAML somewhat in the past, I decided to get into Vulcan coding and dotNet

4.0 and come back to XAML scripting if and when I required it.

It would appear to me reading books and web material that a number of authors have gotten 'besotted' by a new

scripting way to express themselves, and have lost sight of what WPF really is.

This does make it difficult for us coming new to WPF, when everything we pick up in the bookshop is

trying to teach us XAML.

A simple observation of the 'untidiness' of XAML script created by the VS2008 designer (code behind) would

suggest to me that they (Microsoft) expect most folk to use an IDE layer to create XAML code in the future.

[ See below for supporting images. ]

Sure, there is a good intellisense in the XAML editor, but just remember what happened with HTML.

[ See below for supporting images. ]

It is now VERY possible to create web sites with nice GUI and interactive tools, which means the developer

does not even need to see HTML script any more.

I use Help & Manual 5 (Pro?) to make my web area files. The whole process is very easy indeed, easier than

using Word. I am just glad I listened to friend John Parker when he said to get the fuller version of H&M5 -

the one with the web publishing option.

If you use these session notes, along with the 'ClickStartWPF' eNotes, then you will get a foot into WPF

much faster than other ways I feel.

Good Luck.

PHH

===========================================================================

Is This for Developers ? :

Why is This Readable ? :

Look at the script lines below to see the easier to read DatePicker section - this is like this because I bothered to

edit it and insert lots of returns.

Now I can read it.

Intellisense within the XAML Editor :

========================================================================================================

Which leads to this below :-

=====================================================

See you in the next subsection.


Learning Support for WPF in Vulcan

To be quite honest with you, unless you can find books that I could not, I would suggest leaving

books on WPF to one side for the moment - until you get some experience and success under your belt.

If it is Vulcan coded apps using WPF technologies that you wish to design and create, I suggest you use

these notes to get you going (as well as ClickStartWPF) and come to the texts shown below at a later

stage in your personal development.

Before I get to suggesting some books for holiday reading ;-) let me tell you how to get the ClickStart

eNotes from my web site.

Quick Access to ClickStart volumes

Home page for ClickStartVulcan.net

Use the live links above to access the eNotes on WPF and XAML, as well as the demo and working

VS solutions using WPF technologies. The eNotes called ClickStartXAML will appear towards the middle

or end of 2010.

============================================================================

Books Available :

[ images courtesy of Amazon.co.uk ]

Considered a bit of a classic is the Adam Nathan offering from SAMS.

However, on Amazon at the moment the price has been slashed (halved) so there may be something in

the pipeline - like a new edition !?

The absence of a 13 digit ISNB would also suggest 'age' !

[ ISBN 0-672-32891-7 ]

==================================================================================================

To accompany this, and of the same ilk (date and time issue) is a text on Expression Blend.

This text by Brennon Williams is for an earlier version of Blend than is available today, but ought to

prove to be a useful starting point - look out for later versions.

Published by SAMS it has an ISBN of :-

[ ISBN-13: 978-0-672-32931-9 ]

[ ISBN-10: -0-672-32931-X ]

=========================================================================

This next text is more recent, dated 2009. I will use this to get into WPF with XAML if all goes to plan.

By Rob Eisenberg & Christopher Bennage.

[ ISBN-13: 978-0-672-32985-2 ]

[ ISBN-10: 0-672-32985-9 ]

==========================================================================

A text on Silverlight - the one I got the Puzzle Game from - is by Laurence Moroney :-

[ ISBN-13: 978-0-7356-2528-0 ]

[ ISBN-10: 0-7356-2528-X ]

=============================================================================

Now a reference book on XAML, and it may be dated, so look out for later editions.

Prize slashed on Amazon UK to about 50% so an updated version may be arriving soon !

by Lori A. MacVittie and published by O'Reilly :-

[ ISBN 0-596-52673-3 ]

=============================================================================

And now a VERY recent book - published 2010 - by SAMS and written by :-

Paven Podila and Kevin Hoffman.

This looks like a "MUST HAVE" if we are to get past survival mode with WPF. Making our own WPF controls,

that sounds cool in itself !

[ ISBN-13: 978-0-672-33033-9 ]

[ ISBN-10: 0-672-33033-4 ]

===============================================================================


Acknowledgements & Thanks

Paul Piko has had a big influence on my progress and success with WPF, and so I owe

him a lot indeed. Many thanks once again Paul, but don't forget I will still need your advice !

Alwyn and Terry, from my local (Bristol and London) VOUGs have supported me and pushed

me gently in the right directions over the last few months.

I have seen presentations from both these guys, before I ever gave one ;-)

The rest of my progress and success is down to good old dotNet itself. Once you realise how to

get a foot in the door with WPF technologies, dotNet experience just helps to unlock it.

I must not under estimate the support Alwyn (Jennings-Bramly) has provided over the weeks and

months. A BIG thank you 'AJB'.

PHH - 8th. May 2010.


What is WPF, and Do We Need it ?

Two Important Questions :

What is WPF, and Do We Need it ?

Although this is simple enough in itself, it seems as though few people have either attempted to

answer them, or have tried and done so 'badly', or even 'wrongly' , in my opinion.

For example, there are many fine looking books that come as "Teach Yourself / Learn WPF" in general

nature, and then for the first 50 pages (or more) they seem to focus on XAML scripting, and little else.

No dotNet type syntax at all.

After putting in many hours work, and had many success too, it would seem to me that I have an answer,

or two, which at least I am happy to work with myself. I offer these to you too.

Question Two :

To make things easier for you, I will answer the second question first - "Do we need WPF?" - and the

answer is simply YES, we certainly do.

At first, I thought I would end up using WPF as well as Forms, and probably doing most of my development

in Forms, which is what I knew and also with which I am most comfortable - or was!

Now that I have used WPF a little, and gained some valuable experience with it, I have changed my mind.

I will now stop using Forms, unless I have to for some reason, and do nothing but WPF development in the future.

Why ? Simply because Microsoft have provided a whole bunch of support technology for WPF in the dotNet

4.0 namespace, and this has been well designed, and consistently and logically thought through. This only

becomes obvious when you start to use WPF classes 'for real'.

If you like, they have gotten it right this time around. It makes my life as a developer much easier, and is nice to use

at the same time.

Many of us are probably only too well aware that Forms had some 'historical' parts to it, some parts of

dotNet 2.0 and earlier, which simply looked and 'felt', quite dated - if not old fashioned. The underlying technology

was simply not good enough for today and the future. Forms is actually quite old - ten years ?

Question One :

Put quite simply, and correctly in my opinion, it is a whole bunch of dotNet classes which support a new GUI.

Yes, the whole of WPF has dotNet classes associated with it, and so we can write dotNet code, which is

what many of us have lots of skill in doing previously. I am comfortable with dotNet and how to code with it

using Vulcan syntax, so I am more than happy with what dotNet 4.0 has to offer me.

Lets get this straight, WPF is not XAML. And in fact WPF applications can be created and run which have no

XAML script at all. An example of this is included in the working examples folder.

However, it would be silly to push this to extremes as Microsoft have created two GUI designers around XAML

scripting as their 'code behind'. More of this in later sections.

Summary :

After much trial and experimentation, I have decided that I will use WPF and supporting technologies from now

on to create any new applications I require.

My development environment has got richer and more pleasant to use, at the same time as me being able to

use all my previously acquired dotNet coding skills.

Note :

See the sub-folder to find out where I got my CHM file from on the beta SDK documentation - this is more than

helpful or useful, in my opinion necessary.

PH - 7th. May 2010.


SDK documentation for WPF ...

Study these short notes and images, and grab yourself a bunch of help notes etc. And use them!!

I was lucky enough to find this link :-

http://blogs.msdn.com/wpfsdk/archive/2009/05/21/offline-wpf-net-framework-4-documentation.aspx

CHM file download dotNet 4.0 documentation

Use the live link above to download the CHM file which then opens and displays as shown below :-

I have used this extensively for the last four months and found it most useful and helpful, while making

some good progress I feel.

Searching is easy, and there is some good background type information to aid our general understanding of the

new technologies with which we need to come to grips.

Below is shown a section on 'Flow Documents' :-

And below we see an image which tells us of the new DatePicker control.

Early versions of WPF namespace(s) had no such control available. This one is to be found in the "WPF Toolkit"

section of the designer toolbox, along with two other new controls, DataGrid and Calendar.

try http://msdn.microsoft.com/en-us/library/w0x726c2.aspx

MSDN - on-line information.

========================================================================================================================================================================

http://msdn.microsoft.com/en-us/library/system.windows.controls.datepicker(v=VS.100).aspx

Find WPF controls ....

If the links work as expected, you will see something similar to the image shown below :-

=======================================================================================================================================================================================================

Drilling down deeper we get details on the DatePicker properties as seen below :-

======================================================================================================================================================================

Please don't underestimate the value of these SDK type notes and web / CHM documentation resources.

If you are doing things right you will always have these open and available on your desktop, as well as

spending a lot of time reading them and using them to do your development.

This is one skill I have had to force myself to acquire while learning dotNet. There is not a 'book' alternative!

Assemble yourself a desktop folder for stuff which is not in the VS help, or in your browser favourites. Below

is an image of mine, however it looks a bit dated by now :-

You may notice the 'V3 Local' tool - this was a forerunner of the ClickStartExec link to all ClickStart volumes

of the eNotes I have compiled for myself.

Now I use the live link as a source of my 'copy and adapt' ideas and code.

An old Music master of mine at school said ... "Don't remember the details, just remember where to go to

find out all the details quickly !" And this still applies some decades later - its an information skill, not a

computer or web skill.

Good Luck with you information hunting !


What is XAML, and Do We Need it ?

Once again, let's answer the second question first.

The short answer is NO, we can create WPF apps without XAML, and an example is included in the folder

for the working examples, later.

So WPF stands on its own without XAML.

WPF is a complete dotNet 4.0 namespace and has all the classes to create GUIs with the enhanced WPF

supporting technologies.

However, having said that, the two Microsoft designers for GUIs using WPF, are written in such a way as to

generate 'code behind' which is all XAML based - no other alternative available.

The designers I refer to are those within Visual Studio 2008 and 2010, as well as the special design tool called

Expression Blend. Currently the Expression Suite is at version '3' so the image in the sub-solder next, is of

Expression Blend 3.

So although we as developers could live without XAML if we tried hard to, it is not a totally practical approach

to take.

So why all the fuss ? Why does XAML exist at all ? The reason apparently is the "Unified Interface" or 'UI'

for short. Microsoft (Bill 'g'?) wanted to have one way of designing and writing GUI screens for a long time.

By having XML script (yes, XAML is XML) the instructions can be sent to a distant client and on that platform

the Silverlight version of the GUI is rendered by the web browser. Yes, Silverlight is WPF and as it now stands,

the power and flexibility of Silverlight is getting quite close to that of WPF within Windows 7.

XAML is a declarative form of scripting and is not 100% of what WPF dotNet code can do, or 100% of what the

WPF dotNet classes are / contain. XAML is good at setting up GUI but falls short at runtime in certain respects.

It is what it is, and does it well, just don't mistake XAML for WPF - and many texts don't explain this !!

So Vulcan and C# code can be used to write a dotNet form of all XAML script, but XAML script can't describe all

of what may be coded in Vulcan, C#, or any other full dotNet language.

My Initial Strategy to getting into WPF :

I have discovered a way to get into WPF easily, without the need to become master of XAML scripting first.

At the moment I use the designer tools from MS to place controls on the window where I require them. However,

I then do all my 'setting up' coding in Vulcan. This seems to work fine, and I have done some suitably complex

or involved applications this way. certainly enough to see the power and functionality of WPF.

In time, as I see what my needs are with Silverlight and creating web services, I may well throw more of my efforts

into mastering XAML scripting. I am aware that the syntax for writing XAML is very neat and short, in comparison

to Vulcan and C#, but it does 'mask or hide' the reality of the dotNet underlying classes.

As one knowledgeable web article said, if you need to know how to code everything in dotNet, then why run away

from the necessity because it seems easy to write a bit of XAML. In the end, for program flow, and changes at runtime,

the developer will need to have all the dotNet skills for dotNet 4.0 as much as he / she does for all the rest of dotNet.

So my personal approach is to gain the dotNet skills first, get into using the extra power and flexibility of WPF, then

add on any extra XAML scripting skills, as and when required. I certainly intend to do so.

I will start a 'ClickStartXAML' later this year so look out for it around October / November time (2010).

Oh! by the way, there does not seem to be a way to convert XAML script into Vulcan.NET (or C# for that matter) by

using clever plug-ins like Fabrice's Reflector tool.

The good news is however, that there is a very good intellisense in the WPF designer, while writing and editing XAML.

Also if Microsoft provide and maintain the designer tools, we will have less issues at a Vulcan and Grafxsoft end it

would appear to me. Less room for integration problems previously seem with Forms 2.0.

Finally :

I could say "what has changed", regarding the way I use the GUI designer. I have to confess I always preferred to use

the design surface to simply select and position controls, and then do all my other initialisation in code. I even did

this with the Visual Objects designer, which I liked a great deal - and spent zillions of hours using ! And certainly did

this also for Forms 2.0, in both VIDE and VS.

See you in the next subsection.


Expression Blend


Silverlight


WPF apps with No XAML !

Well, here we are, I did warn you, an attempt to show that XAML is not necessary for WPF to work.

I have my good friend Alwyn (Jennings-Bramly) to that for the link to the web.

AJB found out a lot of good and great stuff while researching his Vulcan book I strongly suggest you buy a

copy ASAP - it is well worth the investment, no matter what it costs. I know what went into it - a LOT !!!

=======================================================================================================

Okay, if we were pig headed and/or stupid, we may wish to do an even more impressive XAML free

example (or two) - but what's the point once we know ?

PHH - 8th. May 2010.


What Does dotNet 4.0 Offer Us ?

DotNet 4.0 has namespaces for all the WPF GUI 'stuff', both window and controls.

However, it also has all the necessary supporting classes, which are not necessarily just

for WPF. In some respects Microsoft have taken the chance to put a few things right, and

make improvements. A good example of this is the class 'DragDrop' as shown below :-

===========================================================================================================================================================

Although this class is in the namespace 'System.Windows' and assembly PresentationCore.dll, it will

work with earlier technologies on a GUI platform, and useful it is indeed.

I have done some Drag Drop with WPF and it is greatly improved over the Forms 'flavour' mainly due

to this new class.

Don't ask ... "why did they not include this before?" .. deeper mysteries of the Universe, springs to mind ;-)

I think you will find that as we use WPF more, and learn how to get more successes with it, we will see

how to leverage more of the unseen power from the underlying dotNet 4.0 classes. It would appear that

they is much more on the documentation front which may fall into this category.

So although this entry is somewhat short at the moment, I don't think it is because it is unimportant, just that

the details are yet to be discovered.

I will attempt to revisit this topic as I become more enlightened in the future.

See you in the next section.


Can We Mix Forms and WPF ?

The short answer to this simple, but very important question, is YES !

Not just can we get the controls to show in a "cross manner" - i.e. Forms controls on WPF windows, and WPF

controls on Forms, but the events trigger correctly and can be used as easily as normal. Unfortunately,

I have not had enough time and opportunity to explore this as yet, so more on events and handling in this

'cross manner' will need to be added to ClickStart eNotes at a later date - later this year.

Below is the 'BellsAndVulcans' demo app after I have adapted it to take a Forms third party control

from the publicly available ZedGraph library.

It will be helpful to you in following through this interoperability chapter, if you use the following images

and icons to distinguish between a Form and a window 'screen' - 'screen' being the general term used here

for a GUI of any type, be it VO, Forms or WPF.

First the Forms three coloured square icon :-

==========================================

Now the WPF 'window' icon :-

=========================================================

Chris will have to show us what a VO icon is like, I have forgotten after seeing his good session in Stuttgart.

On the 'Bells and Vulcans' main screen we have a push button to launch a Form, as well as a couple of controls which

do not come from the WPF toolbox.

There are two Forms controls, these are showing below :-

[ look at the calendar image and the graphical representation ... ]

The first is the date time picker control, which at the time was absent from the available WPF controls

in the toolbox on offer - however this is now remedied, and in the VS2008 version I am currently using appears

in the WPF toolkit as shown below :-

==========================================

Notice the DataGrid too, which I have used in the eNotes in 'ClickStartWPF' to great effect, as in the WPF app

called 'BESTinvoices' and 'SmallTrader'.

I suspect that there will be no need to use standard Forms controls on a WPF window in the future, as all basic

functionality, as well as much improved and extra capabilities, will be available as standard WPF 'stuff'.

However, there will probably be a need to access Third Party tools via their Forms controls for quite some time,

or at least until they (the third party) provide suitable WPF compatible controls.

This is why I chose to show the ZedGraph control hosted on a WPF window.

In order to 'host' a Form control on a WPF window we need first to select and place an "ElementHost" control from

the WPF Interoperability section of the toolbox - see below :-

=======================================================================

We place and size the 'ElementHost' as we would any other control on the WPF designer surface.

Please note that we can also place a host control on a Form to take a WPF control, and this is found in

the System.Windows.Forms.Integration namespace - see below for an example :-

========================================================================================================================

To see more about hosting, and see real live examples of both 'ways around' see the following sub-sections.

It is more likely that, in the immediate future, we have needs to put WPF controls on Forms, so we can leverage some

of the extra functionality, power, and flexibility, from newer tools on our already existing Forms.

However, I suspect that quite soon many of us will just simply move over completely to using WPF stuff 100%

That is how it feels to me right now - now that I can get my fingers into all this stuff and get the dotNet to work

for me.

See you in the next section.

PHH - 15th. May 2010.


Forms from Windows, and Windows from Forms

Okay then, this is easier than the easy bits.

In order to launch another screen from either a VO, WPF or Forms GUI it is quite simple. We

make a standard push button control for that particular format of the GUI screen, instantiate a

subsequent GUI class which happens to be different in GUI format from the screen launching it.

There is no big deal, unless you were hoping to have events pass back and forth, but most often

that is not what we as developers wish to happen. So it is easy.

Let us look at the 'Bells and Vulcan's app as an example :-

And what does the code behind this look like ? See below :-

=================================================================================================================

As you can see, nothing unexpected, just launching another screen in a non dialog mode.

So what of the button on the WPF window which is launched as a result of this ? See below for this

button :-

The code to go with the click event handling for this button is as shown below :-

==================================================================================================================

As you may have noticed, we can use this test app to launch one from another and so on ad infinitum - just make

sure the flees don't get you !

Who says WPF is not like "being bitten by the bug" !?

================================================================================================================================

I am sure you could extend this to include VO screens also. It is just I have not had the opportunity to research

into this, as my paid work (on which I base most of me eNotes and research) did not take me into transportation

and reusing VO code from previous working apps.

It can be your homework task to add VO screens into this and more buttons, etc. etc. .....

Good Luck.

PHH - 15th. May 2010.


Interoperability - Mixing Controls!?

We have had a brief look at the way that interoperability works, in the introduction section of this chapter.

Both a Form and a WPF window need to first have a hosting element (or control) placed on the surface, as you

would normally place a standard control. This is also sized and anchored or docked, as per usual.

Then to make a link, between the hosting 'screen' and the hosted control, we need to add some code.

Let us look here at what this looks like to place the ZedGraph control on the main window of the 'Bells

and Vulcans' app :-

========================================================================================================

The host element is named 'owfhTest13' and this is my personal naming of 'object windows forms host - Test13'.

Remember where the element came from :-

========================================================

And this is how things look in the WPF designer :-

============================================================================================================

[ ** note ** the tidy formatting was done by me, and my 'fat fingers' ! ]

[ the important bit to notice is the 'Name' property - it matches or Vulcan coding ... ]

We will see more of this in the next subsection on Forms controls on a WPF window, where we also

place a couple of other controls like the MaskedTextBox, just for good measure.

Before we move into the subsections to see extra details and new examples, let us see what the Vulcan

code looks like for the element host on the Form launched from the push button called "Go To Forms 2.0"

at bottom left of the main WPF window :- [ first the image ... ]

============================

Which gives this form and control :-

===========================================

And now the Vulcan code :-

======================================================================================================

This is in the 'InitializeComponent' method of the Form. Note that we have not added a child WPF control at

this point, and this is why we see a 'blank' type of output - see below :-

==================================================

Don't worry about the NULL property association / assignment, you will see plenty of real and useful stuff in

the sections to come ;-)

Now lets move on.

PHH - 15th. May 2010.


Forms Controls on WPF windows

Let us take this opportunity to make from a completely fresh start, a new WPF window app which

uses three different Forms controls. This will be a demo app, so will not do anything useful, or

meaningful - but fun none the less ;O)

In Visual Studio (2008) close any open project or solution.

Now start a new Project/Solution as below :-

==========================================================================

Then enter the details as shown in the following image :-

Once you enter the project name correctly, you should see something like the following on screen :-

=============================================================================================================================================================================

You may have fewer sections (folders?) within the toolbox area, that will be the only difference, if all

has gone well.

Now drag a 'WindowsFormsHost' onto the design surface and place and size similar to that show in

the image below :-

Go into the Properties Pane (PP) and give the host control a more suitable name - something like

that show below :-

=====================================================================================================================

Now add two more, place and size, and suitably name.

You should try to create something like in the image below :-

==========================================================================================================================

Notice I use the Document Outline (DO) floating window (pane) which is found as show below, or by pressing

Ctrl+Alt+T :-

==========================================================================================

Quite often, particularly when quite a few controls and elements are present on the design surface, it is

easiest to select a single control and place it in focus, by using the DO and clicking the required element

in the DO pane.

Note that the XAML editor, designer surface, property pane (PP), and the DO are all linked in real time,

as interactive selection is made. They are all context 'aware' to user inputs, both mouse and keyboard.

Now time for a first trial - press Ctrl+F5 to compile (build) and run the app.

You should get this VERY interesting and exciting output to you display :-

Well, we don't have to do much dotNet coding to improve this, a lot ! So let's keep going !!

Take a look at both some of the code and also the result obtained - in the image following :-

=======================================================================================================================================================

The main window has also had some colour added to the background, and the caption and object name

given something more meaningful too.

============================================================================================================================================================

Before we add the slightly more difficult ZedGraph third party control, we can add three labels to the

screen (WPF window) to make it more friendly to read and understand.

Go into the WPF designer and add labels from the toolbox to make your window look like below :-

====================================================================================================================================================================================================

Looking at the basic output above, we seem to have made things a little better, as well as making sure

that the screen resizes in a suitable manner.

Now we need to add the third party ZedGraph control to our final, and as yet 'spare', host element.

Preparatory 'Stuff' :

In the menu bars of the VS environment, change from Debug to Release. Rebuild and run, close the app.

Locate the ZedGraph files and information from :-

CodeProject - Link for ZedGraph

============================================================================================================================

Copy the downloaded files into the same Release folder, and you should have something like

that shown below :-

===============================================================================================================================================================

It is the 'dll' files which are crucial for getting our ZedGraph control to be available to us.

Now that we have the 'dll' files available, move to the SE pane and right click 'References', and the click to

"Add a Reference" - then select the 'browse' tab.

Navigate to the Release folder using the menu bar icons and you should see something similar to the image

shown below :-

For good measure, add the other 'dll' even though we may not really require it for this simple demo.

When you have succeeded the SE pane should look like this :-

================================================================

[ *** Note *** a word of caution, with VN 161.1 there is an issue with adding extra References,

and sometimes the WPF designer will not open correctly. This is known by 'Team Vulcan' and will

be put to rights quite soon. For now I have a survival technique which involves removing extra entries

in the references, opening the windows, and then putting the References back.

Yes, it is a fiddle, but it works, and all of the rest of the power of WPF is then available. ]

Good News :

Okay, we are doing fine, and so for some good news ....

The ZedGraph control is set up to do it best 'at all times' to show something meaningful when displayed.

So we get an output which is 'graphical' even with no content supplied by ourselves ;-)

So, lets get something, even though it is empty as such, and worry about data later.

What we need to do is write some Vulcan code to instantiate a ZG control and pass this to the 'child'

property of the hosting element. Let's give this a go .....

Add three lines of VN code to the 'Initialize' method we used previously. It should now look like this :-

===================================================================================================

Line 43 will be used later to add some real data to our graphical control.

For now let's just build and run to see what we have. View the image below as this is what we

now have after building the app - to go with the notes being written as the coding was taking place :-

So there we have it, step one has been to place three different (but still empty) Forms controls

on a WPF window. Two standard, and one a third party.

======================================================================

As in the image above, make sure you add the namespace to the beginning of your file "Window1.xaml.prg".

Now uncomment the line which was 43, now 45 in my code after adding the #Using lines.

Finally add the necessary ZG code which was a standard example from the CodeProject in C#, translated by

myself to get some working Vulcan code. I did nothing clever - just copied and adapted.

Here is the VN code :-

==============================================================================================================================================

Finally we need the live output to see what we have created - or should I say copied and adapted !?

And 'super' finally, lets add a couple of lines to force some content into the other two controls

at startup time :-

==============================================================================================================

And this is what we see :-

Time to move on to see the other side of the coin - as it were - how we can get WPF controls

showing up in Forms screens.

See you there.

PHH - Saturday May 15th. 2010.


Some useful working code

#using System

#using System.Collections.Generic

#using System.Linq

#using System.Text

#using System.Windows

#using System.Windows.Controls

#using System.Windows.Data

#using System.Windows.Documents

#using System.Windows.Input

#using System.Windows.Media

#using System.Windows.Media.Imaging

#using System.Windows.Navigation

#using System.Windows.Shapes

//==================================

#using ZedGraph

BEGIN NAMESPACE WPFhosting3FormsControls

/// <summary>

/// Interaction logic for Window1.xaml

/// </summary>

PARTIAL CLASS Window1 INHERIT Window

CONSTRUCTOR()

SUPER()

InitializeComponent()

self:Initialize()

RETURN

PRIVATE METHOD Initialize() AS System.Void

local oMTB as System.Windows.Forms.MaskedTextBox

oMTB := System.Windows.Forms.MaskedTextBox{"00/00/0000"}

self:owfhMaskedTB:Child := oMTB

local oRTB as System.Windows.Forms.RichTextBox

oRTB := System.Windows.Forms.RichTextBox{}

oRTB:BackColor := System.Drawing.Color.AliceBlue

self:owfhRichTB:Child := oRTB

oMTB:Text := "13/03/1970"

oRTB:Text := "Hi guys, look what we have done together !!!"+CRLF

//------------[ Setup the Graph ]------------------

local ozedGraphControl1 AS ZedGraph.ZedGraphControl

ozedGraphControl1 := ZedGraph.ZedGraphControl{}

self:owfhGraph:Child := ozedGraphControl1

self:CreateGraph16(ozedGraphControl1)

//-------------------------------------------------

return

METHOD CreateGraph16(zgc AS ZedGraph.ZedGraphControl ) AS VOID

// ----- get a reference to the GraphPane -----

LOCAL myPane AS GraphPane

myPane := zgc:GraphPane

// ----- Set the Title and Axis labels -----

myPane:Title:Text := e"Demo of Labeled Points"

myPane:XAxis:Title:Text := e"Time, Seconds"

myPane:YAxis:Title:Text := e"Pressure, Psia"

// ----- Build a PointPairList with points based on Sine wave -----

LOCAL list AS PointPairList

list := PointPairList{}

LOCAL i, count AS INT

count := 15

LOCAL x,y AS Double

FOR i := 0 UPTO count

x := i + 1

y := 21.1 * ( 1.0 + Math.Sin( (double)i * 0.15 ) )

list:Add( x, y )

NEXT

// ----- Hide the legend -----

myPane:Legend:IsVisible := FALSE

// ----- Add a curve -----

LOCAL curve AS LineItem

curve := myPane:AddCurve( "label", list, System.Drawing.Color.Red, SymbolType.Circle )

curve:Line:Width := 2.0

curve:Line:IsAntiAlias := TRUE

curve:@@SYMBOL:Fill := Fill{ System.Drawing.Color.White }

curve:@@Symbol:Size := 7

// ----- Fill the axis background with a gradient -----

myPane:Chart:Fill := Fill{ System.Drawing.Color.White, ;

System.Drawing.Color.FromArgb( 255, System.Drawing.Color.ForestGreen ), 45.0}

// ----- Offset Y space between point and label -----

// ----- NOTE: This offset is in Y scale units, so it depends on your actual data -----

LOCAL offset := 1.0 AS Double

offset := 1.0

LOCAL pt AS PointPair

LOCAL text AS TextObj

// ----- Loop to add text labels to the points -----

FOR i := 0 UPTO count

// ----- Get the pointpair -----

pt := curve:Points[i]

// ----- Create a text label from the Y data value -----

text := TextObj{ pt:Y:ToString( "f2" ), pt:X, pt:Y + offset, ;

CoordType.AxisXYScale, AlignH.Left, AlignV.Center }

text:ZOrder := ZOrder.A_InFront

// ----- Hide the border and the fill -----

text:FontSpec:Border:IsVisible := FALSE

text:FontSpec:Fill:IsVisible := FALSE

text:FontSpec:Angle := 90

myPane:GraphObjList:Add( text )

NEXT

// ----- Leave some extra space on top for the labels to fit within the chart rect -----

myPane:YAxis:Scale:MaxGrace := 0.2

// ----- Calculate the Axis Scale Ranges -----

zgc:AxisChange()

RETURN

END CLASS

END NAMESPACE

====================================================================

PHH - Sunday 16th May 2010


WPF controls on Forms

Okay guys, lets take a look at some output from a test and demo app - one made

simply to explore the possibilities, and look at some aspects of documentation in the

world of WPF.

Study this image to see what it has to offer :-

Above we have a Form, and on it are three controls which belong to the WPF toolbox, and which

are hosted in suitable 'hosting controls'.

Here is another image which may be helpful to understand what is going on :-

======================================================================================================================================

As seen in the image above, one label and three hosts.

=============================================================================================================================================

Notice that the Properties Pane shows we have as a child property association, the 'UserControl1' class.

Let us look at the parts of the VS shell which tell us more about what is going on here :-

==================================================================================================================================================================

The Solution Explorer (SE) pane tells us we have two User Controls in the 'WpfControlLibrary'. One is

for a Flow Document Reader (as shown directly above) and the other is for a RichTextBox - don't get

mixed up between the RTB of the Forms 2.0 variety, as the two are quite different.

So to summarise, it looks as though we need a WpfControlLibrary with one or more suitable User Controls

within that.

Now let us look at the RTB User Control in more detail :-

==================================================================================================================================================================

Now, all we need to see extra to this, is what we do to fill the three controls with suitable data, or content.

Here are the code lines which do the trick :-

===============================================================================================================================================================

Finally, here is a snap shot of the physical file folder showing the data files within the same folder as

the main application EXE file - also note the existence of the WpfControlLibrary 'dll' file. Remember this is

referenced by the app itself.

=============================================================================================================================================

And VERY last of all, here is the running output when a few changes have been made to screen size and

page display, as well as detail sizing of text etc. :-

Good Luck with your interoperability, do have fun, it is very productive once you get the hang of it.

PHH - Saturday 15th. May 2010.


A Challenge !!

Okay guys, are you up for a challenge ?

I will outline just what it is that I would like to be able to do, and then do it along with these notes.

The Problem :

In the Forms GUI toolbox there is a report 'viewer' control, see below :-

=====================================================

[ don't ask why it appears twice ! ]

This control is very useful as it allows users to easily see (by a click of mouse button) reports based on SQL

data - and these reports can be simple as well as quite complex. [ Reporting Services is Microsoft's name for this technology. ]

Here is a sample of what we can produce - this is a C# Forms applet, for demo purposes :-

We simply have two 'MicrosoftReportViewer' controls on one form, side by side.

Each 'viewer' is set to display a different report.

The challenge exists at the moment (May 2010) for two reasons. There is not apparently a 'ReportViewer'

control in WPF at the moment - well I can't find one anywhere - and also the existing 'ReportViewer' will not

work in Vulcan because a necessary interface is not yet supported.

So if we wish to show a report from SQL Server on a WPF window, we need to use a hosting element to allow

us to use a Forms control, and that control needs to be a "User Control" based on C#.

For most of us quite a challenge - and on top of that the VS / Vulcan integration I am using with VN 161.1 is

flakey, and somewhat difficult when items are added into the References list in the SE pane. No point in moaning,

or saying much more as it will be rectified very soon I believe.

Okay then, first things first. Let us take our test applet from the previous section, and add a push button :-

Let us add VN code to the 'Window1' class so that clicking this button will launch a second (child) window

on which we can put a hosted "User Control".

Here is some useful code :-

==============================================================================================================

So clicking our new push button does this for us :-

And all we need to do (somehow) is make a second window and a "Windows Forms Control Library" of a C# variety.

Let use see what we may be aiming at, and how it works, before we go through each step to create a similar one

ourselves.

First of all, let us study the SE pane :-

=============================================================

For the moment, ignore the Data Set collapsed entry, as this can be dealt with later, and is not really part of this

challenge, but is nice to display some real data rather than show an empty control.

Look at the little icons to the left of each line in the SE pane. You will notice that the project is called

"WindowsFormsControlLibrary1" and it is of a type C#.

Looking further down the list we see the only designer entry is "UserControl1.cs" and this looks as follows :-

==========================================================================================

Sorry it is so large and empty, but the downside of the Forms designer is there is no slider control to allow

users to shrink the image of the GUI being created. So we will have to live with this, at least until we give

up forms technology for the superior WPF 'stuff'.

What is the image we see ?

It simply is a 'ReportViewer' control from the Forms GUI toolbox, positioned on a User Control surface.

Yes, don't confuse what you see with a Form, it is not, it is a 'UserControl' - see below to understand more :-

[ There is a grey gird which is a design surface, so that complex UC can be constructed. ]

=========================================================================================================================================================

And to see what we can produce lets run this demo app with what I already have in place, and tested previously.

Remember, we will look at making a simple report later, to get some slightly different data.

For now focus on the second (child) window, and the ReportViewer control on display - remembering that it

is a Forms control and the whole UserControl is running from C# code. Study this :-

Well, we have what looks like a suitable answer, now we just need to repeat the process of creation, one

step at a time ;-)

Making a New Control Library :

I have collapsed the contents of the SE pane to give us the following :-

==========================================================

Now right click the solution item (top line) and 'Add' a 'New Project' :-

==================================================================================================

Select Visual C# as the Project Type, and from the list of Template options select the one named

"Windows Forms Control Library", and provide a suitable name, as shown below :-

The results of doing this as shown above will look something very close to what is seen below :-

[ .. note the grey gridded design surface for the UC construction .. ]

==============================================================================================

Now we need to size the design area accordingly (large to fit our control) and then drag a copy of the available

'ReportViewer' control from the Forms GUI toolbox.

This time I have made the UserControl (UC) both wider and also less deep than for the first attempt of mine.

Here is what we have for our "try two" :-

==============================================================================================================================

Let us see if we can continue without any report for the moment, and try to get the control displayed, along with the navigation

icons and tools.

First we need to build our library so click to highlight the item in the SE pane :-

=========================================================

Right click and select 'rebuild' as shown below :-

=========================================================

Lets do a little bit more than basic selection and coding, let us change the default name of the UserControl

and make it 'UC2' instead.

I will leave it to your to right click the item and choose the 'rename' option.

You should end up with this :-

=======================================================

Now we need to include a new reference in the references list, so right click the References item in SE,

or in fact you can right click the project itself, and choose option 'Add reference'.

Either way we get the following dialog displayed :-

=================================================================================================================================

After selecting the new 'WFCLibrary2' you should see the new item in the list as shown below :-

=======================================================

Finally, we need to make a couple of code changes and inclusions to tie it all together.

View and study the code below, and see in particular line 16, and 32 - 37 :-

=================================================================================================

I think that is all, so build and run and you ought to get this 'fine' display :-

So as I predicted, we can see we have a UC and a RV control available for use, just no report as yet to view!

We can put that to rights now, after a nice cup of tea to refresh me, and my fingers for keyboard pressing and

mouse clicking.

Back soon.

Making a Report - or RDL File :

PHH - Sunday May 16th. 2010.


Data Binding with WPF Controls

To get the most out of full Data Binding capabilities with WPF we need to have business objects which comply

with the interface called 'INotifyPropertyChanged'.

At the moment we can't do this directly in Vulcan and so I have made my Customer and Invoice class in C# and

made two Class Libraries. Here is the customer class shown in the SE pane :-

===================================

The C# code looks like this :-

===============================================================================================

In the code below notice that event handler 'OnPerpertyChanged' is called from within each property. We

have only listed for us the 'Contact' property, but all the others are similar in this respect.

=========================================================================================================

And here is the event handler itself. This is called from within each property code section.

===========================================================================================================

Below is shown the customer edit screen, alongside the text block controls on the main Invoice window.

Both the main window WPF controls (text blocks) and the sub window for editing (mainly text box controls), are

bound in the standard WPF fashion. We will look into this further in the text following.

If the data fields bound to the input/edit text boxes are changed, then the change is reflected in the text blocks

of the main form, as soon as each character (digit) has been changed.

======================================================================================================================================

In the image below, the telephone number for Andrew is being changed and in real time each digit on

the main screen is changing, and there is just a '6' to be added after the '8' before the new and correct

number has been added.

You will see in the code below that this behaviour could have been altered so that changes were reflected

only when the edit control had lost focus. This is a choice that the developer needs to make. Here is an

example of the code I refer to :-

=============================================================================================================

Changing the property for just the telephone number control we can force the behaviour seen below :-

==============================================================================

Notice this time the whole new and correct phone number has been entered and yet the main window still

shows the original information. This is because the control still remains in focus.

You would probably choose this approach if the control was one with a lot of text information, and updating

other bindings on a character by character basis did not make a lot of sense, and may also affect performance.

Below is shown necessary portions of the full code solution, related to this data binding :-

===============================================================================

...............................................................................................

...............................................................................................

====================================================================================================================

...............................................................................................

...............................................................................................

..........................................................................

..........................................................................

============================================================================================================

Notice in the code above that we have set the binding mode to 'TwoWay', this can be set to 'OneWay'

and you would need to experiment with this if you wished to restrict the full behaviour as seen above.

Now lets move on to see if we can get any sort of data display and binding between a Form and a window.

See you in Interoperability.


Interoperability - mixing Forms & Wins

If we concentrate on GUI controls which have data source properties we see we can get some shared data

binding 'capabilities' rather easily. I use the word 'capabilities' advisedly, as we do not see navigation as

we may expect. However, lots of other stuff is there to see and use. Lets see an example.

Sharing a Data View :

The demo application called "BindingEGsDT1" is shown on screen below. {See the top right icons show

that the screen beneath (as layered one over another) is the Form, and the top most screen a window.}

This demo is comprised of a Form being called from a WPF window class, both sharing the same 'view' object.

This view object is built around the data source, and then it is associated with the properties for data source

in both the DataGrid (WPF) and the DataGridView (Forms).

==========================================================

Below is the code to create the view and pass it to the property of the DataGrid, before it is passed as a parameter

into the 'ApplyView' method of the Form class.

==============================================================================================================

And now the code is shown (below) which sets the view as the data source for the Form's DataGridView

control.

=================================================================================================

Although a lot of 'behavioural overlap' is seen from Form to window, and vice versa, as the data is changed in many

different ways - as demonstrated below - there is no synchronisation between selection of records.

Some may say there is no navigation associated in this way of doing things.

I have not had enough time as yet, to explorer this aspect more thoroughly, but was surprised to see the amount

of common behaviour that I did.

Editing Cell Content :

Below the cell at bottom left of the WPF data grid is being edited - the '40-3113' entry. Note that until

the focus is lost the data in the Form control (DataGridView) does not reflect the change :-

Moving the focus away from the cell which has changed, we see the changes appear in the Form control

as well.

Setting a Filter Condition :

The WPF window has controls to allow users to set filter and sort conditions.

Below is an image taken just after a filter has been applied - see that it is already displayed as text in the combo box.

Check that the 'ItemNo' column is the same in both Form and window.

=====================================================================================================================

Applying a Sort Condition :

With the same filter applied as above, we have now applied the descending sort condition, on the 'ItemNo' column.

Notice once again that there is an exact correspondence between the data rows.

=========================================================================================================================================

Removal of a Column :

Using the functionality built into the WPF window we see we can remove the 'ItemNo' column and this

change is immediately reflected in the Form's DataGridView control.

Editing within the Form Control :

So far we made our changes within the WPF window control - the DataGrid.

Now we will see what happens when we try some changes using the Form control.

Let's try selecting a row in the DataGridView control on the Form, and the deleting it :-

===========================================================================================

The record, or row, for the 'S162' item is selected. Then the delete key pressed.

Here is the result :-

========================================================================================

And then subsequently to this I have clicked in the header of the 'ItemNo' column and applied

a descending sort - as seen by the icon in the column header.

Once again, note in the image below that there is a correspondence between the rows :-

==========================================================================

It is worthy noting that we have used the basic view associated with the DataTable object for this example.

===============================================================================================

There are other view classes which exist, in both the earlier dotNet namespaces, and the newer one,

so we will need to experiment further with this interoperability. Below is the CollectionView class :-

However, it would seem to me that we ought to be attempting to move over to WPF completely, so we

can get the most out of all of the new and improved technology.

At some time we need to let go of the past !!


What is Needed Now !?

"Objects - saving as such in our data source."

Next best thing is to appear as if we are saving and retrieving objects, and let a 'mapping' do the

hard work for us.

Look at this entry in Wikipedia on 'NHibernate' :-

==========================================================================================================================================================

And now that this sounds cool, we better read on and see the "Feature summary" :-

==========================================================================================================================

And a little bit more as well :-

=======================================================================================================================

After DevShare I will definitely look into this as a way forward. It looks as though this technology will

completely support the new data binding we see in WPF and dotNet 4.0

What is shown above looks VERY interesting indeed ;O))

"Watch this space !"

See you in the next section.

PHH - 9th. May 2010.


Somethings to Improve

Binding of the Date :

At the moment the date picker control is not bound to the new invoice object being created. I would

like to improve this (in my eyes) by making s binding of some sort. I need to experiment !

Below is how the GUI looks at present in the 'BESTinvoices' app. :-

==============================

========================================================

It is only when the selected date is changed that the event being used is 'fired'.

Below is the code which handles this event :-

=========================================================================================

Yes, it works, but I would prefer to use a binding ;-)

The source will be the data picker, and the target the invoice object property 'InvDate'.

I also wonder if we can bind to the label (text property) as a target, but have the extra concatenation

take place also !?

We will see.

PHH - 10th. May 2010


Documents - Modern Formats


Flow Documents

A Simple Way to Tell :

Okay, we will get used to the look of flow document displays, just as we are very used to telling that we

are looking at Adobe Reader, and a PDF file.

However, a simple test is to resize the GUI screen element, as in the images below :-

=====================================================================================================

If the words and elements (text or graphics) change their relation with respect to one another, then the

design was to accommodate 'flow'. This is quite obvious in the two 'static' images above - it is even more

obvious when you see the resize happen in real time ;-)

Out of interest here is an image of the file content being displayed above - look at the blue highlight to see

some familiar text above :-

==============================================================================================================

======================================================================================================

PHH - 10th. May 2010


Fixed Documents

Many of use older developers are rooted in the past, when 'documents' meant printing out information

to a printer of some sort.

Documents to be physically printed on a paper type medium are designed and created with a printer

size as a target - along with orientation, and a number of other parameters which are related to a

definite and fixed layout.

I suspect (as yet) that not many of us have designed an invoice which will print and look good on a

range of output devices, small and large, electronic and physical.

However, this is the challenge of the modern era, when we have small hand held devices capable of

working with internet details and information. View it on screen, and then print a hard copy - that is

what we all need and what, if we are both honest and realistic.

What are they ? :

Most of us refer to 'fixed' documents when we have a fixed target physical output size and orientation.

So I design an A4 invoice to be printed in portrait - quite a common and usual situation at present.

For years I have used a VO, and then VN printing class of my own, which I used to design my fixed

letters and reports for my client's applications.

However, many will use Word, and possibly Excel too.

Since I have not yet done my research into documents in WPF - the options and the possibilities - I

will stick with using Word documents (new and old) as our examples of 'fixed' documents.

A Simple Way to Tell :

When you see text and images displayed in a viewer and scroll bars are visible, then the document is

of a fixed 'type'. See below for a good example :-

Be aware however, just because a display does NOT have scroll bars, does not say that it is a flow

document.

For any 'viewer' display, use t he mouse to drag corners to change the size on screen - either scroll bars

appear (or disappear), or you see the words and images rearranging themselves.

Sometimes a fixed document display may hide part of the output, then this is also a 'clue' to a fixed nature.

See below for an example using the RictTextBox in WPF :-

File Formats - Ready to Print :

We must not get mixed up. or confused by the file format of a document in electronic form which is

'half way' to being printed out on a printer.

By this I mean that the well know PDF file format, and the more modern and increasingly being used

format of XPS (XML format), are file formats which can be made from anything which can be printed

to a printer - not just fixed documents.

So although we need to know about, and handle PDF and XPS, we are not at that point concerned about

whether they are flow or fixed - they have already been printed. PDF and XPS can be thought of as

'print' files. They are the results of printing any document, report, or graphic, to a "virtual printer". We

often talk of 'virtual printer drivers'.

So to summarize, Word documents are fixed, and PDF and XPS are file formats. So we need applets

to allow us to view PDF and XPS files.

Much of this will become clear in the sub-sections of this topic chapter.

Read on !

PHH - 10th. May 2010


Viewing Word Documents

==============================================================================================================================================

PHH - 8th. May 2010.


XPS - Creation and Viewing

==========================================

Viewing - Document Reader :

====================================================================================================

==================================================================================================================================

PHH - 8th. May 2010.


PDF - Creation and Viewing

Enter topic text here.


Drag Drop with dotNet 4.0

============================================================================================================================================

======================================================================================================================


Data Abstraction Layer

WARNING ! ... the above image may surprise a great number of folk !!!

I have been aware for some time that it was considered 'Good Practice' to have the GUI layer, or

screen as we would call it (Form or window to you and me), quite separate from the data source

itself.

In reading drafts of Alwyn's book I learned a lot more about this approach, and was delighted once

I found that it was applied as a natural part of using Data Binding in the world of WPF.

As you may be aware after reading earlier sections of these notes, Data Binding is real easy in WPF

and with dotNet 4.0.

Without being aware of the data abstraction possibilities, I developed the Invoice app in WPF and by

using the Data Binding features available to me - all based on my existing DBF data files from an old

Visual Objects app I had been using for years.

Once this was all up and running, some extra, and different work for a client using SQL and Reporting

Services, made me think of revisiting the Invoices app and not just changing it to use an SQL data source,

but actually be able to switch between the two - back and forth !

Yes, possibly a very stupid idea, but one worthy of demonstrating - just to show it can be done ;-)


Nice Additions - Tips, Tricks & Gotchas

spell checker available to TextBox and other ?

drag drop built in for text controls

simple tooltip property on each control, as well as a window class

drag drop class which has a method to allow better transport of data objects

easy to use tooltips to show underlying data in fuller format - style of W7 !?

Gotchas !

DnD - complex objects (CO). Make sure the CO is made into a 'dll' which is then available to both source and target

==============================================================================================================================================

=========================================================


Topic Areas Yet to be Explored

PHH - 8th. May 2010.


Events - Bubbling and Tunnelling

PHH - 8th. May 2010.


GUI Screen Layout - Flowing

PHH - 8th. May 2010.


Graphical 'stuff' - 2D, 3D and Video

PHH - 8th. May 2010.


Documents - Formats, Flow and Functionality

PHH - 8th. May 2010.


Working Examples


VS2008 Solutions


WPF app and no XAML

Enter topic text here.


Bells and Vulcans


Picture Puzzle


Flow Documents, and Viewers


Invoice Printing app.


Small Trader app.


Working Code for VS Examples


Summary

 Top Previous

- WPF is a big step up from Forms 2.0 in all respects.

- WPF and its dotNet support technologies seem to have been designed from the bottom up, consistently !

- WPF is pure dotNet, so use it as such.

- I will use WPF from now on, for all my new apps and screens.

- Developers don't have to use XAML, and can improve their skills as they progress with WPF.

- Don't let XAML get in the way, but don't ignore it afterwards either !

- Use the VS designer (and / or Expression Blend) for basic GUI assembly, and then code in VN in the editor.

- In order to make a start, don't get fixated - or confused - by the layout features of WPF, come to these later.

- I intend to have a period where I focus on researching GUI layout with WPF, to see what can be done.

- Get into Data Binding in a BIG way - it has a lot to offer, and makes project design much easier - and better !

- Use the new dotNet class called 'DragDrop' - if they made a new class, there must be a need for it !

- Start to build into your GUIs an abstraction layer and use business objects and collections as much as possible.

- Get your hands on suitable dotNet 4.0 SDK documentation - and live in it !

- Start to use Drag Drop - don't be afraid of it, all forms of DnD work in a similar way - so copy and adapt.

- Explore events, bubbling and tunnelling.

- Explore document formats.

- Explore GUI layout controls to make your WPF windows much more resizeable, and friendly to display change !

- Explore interoperability of Forms and WPF, even VO screens too.

PHH - 8th. May 2010.