Showing posts with label WPF. Show all posts
Showing posts with label WPF. Show all posts

Application Class and Main method in WPF

28 comments

I recently ran into an interesting aspect of WPF applications that I had not previously seen.  It started with this error:

Program 'DemoCorp.UI.exe' does not contain a static 'Main' method suitable for an entry point

I had copied an App.xaml file from an existing application into a new application I was creating, because I wanted the resource definitions and thought that would be an easy way to do it.  I then deleted the App.xaml that was automatically generated in the new application, which created the compiler error above.

As it turns out, there's a special output type for the App.xaml file to make it generate the Main method.  Here's an App.xaml in the solution explorer:

Solution Explorer App

If you click on the properties tab to get the file properties for the App.xaml, you'll see something like the following:

ApplicationDefinition Build Action

To generate a suitable Main method, the Build Action must be set to ApplicationDefinition as shown in this image.  As soon as I figured this out, everything worked great.

Book Review: Windows Presentation Foundation Unleashed

1 comments

Windows Presentation Foundation Unleashed (WPF) (Unleashed)

This is the second WPF book I read after, Pro WPF.  It's shorter than Pro WPF (620 pages versus 931 pages) and it does not have the extensive index of Pro WPF.  But I find it is the WPF book I refer to for  examples.  And it's the book with several bookmarks sticking out of it, which means it's the one I've been using.  Since it was not the first WPF book I read, on my first reading, I mostly skimmed the content, looking for new stuff.  Since then, I've returned to read several chapters as review.

One noticeable feature of this book is that it is printed in full color, which in case you somehow manage to miss it, is proclaimed in large type on the cover.  And for some reason, the fact that "Code samples appear as the do in Visual Studio!" is also displayed on the cover.  Of course, the code samples in the book do not match my Visual Studio, since I'm not using the default colors.  The color is helpful in some circumstances, such as when displaying color gradients.   And I like the color in the code.  But when I first opened the book, I was actually put off by the color choices, particularly for the Tip and Warning sections, which make things a little too busy in combination with everything else.

Color aside, there are some excellent illustrations that succinctly show important WPF concepts, such as Figure 5.1 on page 128 which visually describes the vertical and horizontal alignment, margin and padding properties.

I also enjoyed the Warning, Digging Deeper, and Tip sections that contain useful information that does not fit in the natural narrative (although I found myself searching for some of these because the content wasn't indexed).  I also found the order of material presented in this book to be better than Pro WPF, which seemed somewhat out of order.  As compared to Pro WPF, this is probably the better introductory book and may not be as well suited for in depth reference.  At my current level of experience with WPF, it's the book I open up if I want a quick reminder on how a simple things work in WPF.

Book Review: Pro WPF

0 comments

   

Pro WPF: Windows Presentation Foundation in .NET 3.0

This is the first book I've read on WPF, and I think it got me off to a good start.   I got a solid understanding of the underpinnings of WPF by reading the first several chapters.  I started reading this book sequentially, but finally skipped a couple chapters on graphics.  I still ended up reading it mostly from beginning to end.   There were times that I wanted to "skip ahead", but it does seem to be structured so that each chapter builds on the previous (this might also be because this is the first WPF book I've read.) 

After reading the entire book, I do have to say that the order the material was presented is somewhat puzzling to me.   For example, data binding is not introduced until chapter 16, after chapters on graphics and control templates.

I found it valuable that in the early part of the book, notes often refer to better ways to handle things that will be discussed later.  One example is where he is setting the MinWidth and MaxWidth values on several buttons in chapter 4, but has a note referencing styles which are described in chapter 12.  So many times, authors describe primitive ways to do something without referencing the better way.  And then we copy the code and do it the hard way.

Unfortunately, the first bit of code I copied straight from the book had an error...  The second piece of code I used was a nice reusable window template that I used as inspiration for a custom window style.   It worked like a charm, but I did find a bug related to resizing the window.

I liked the writing style and generally found the book easy to read (when it wasn't easy to read, it was because of content, not writing style.)  It has an extensive index.  Given the caveats I've expressed, I recommend this book as both an introduction and in depth reference to WPF.