Windows Presentation Foundation Unleashed

Adam Nathan, Daniel Lehenbauer

Mentioned 36

A guide to Windows Presentation Foundation covers such topics as XAML, controls, 3D graphics, UI elements, and applications.

More on Amazon.com

Mentioned in questions and answers.

Well, i've got a nice WPF book its called Sams Windows Presentation Foundation Unleashed. I really like to read and learn with it. Are there any other WPF books you could recommend?

I've found the following books very useful:

Windows Presentation Foundation Unleashed - Adam Nathan
You mention you already have this book, however I wanted to give my opinion on it. It is a great book for the newcomer - it is printed in full color which is a great help for visualizing both xaml and concepts for WPF.

Essential Windows Presentation Foundation - Chris Anderson
This is also another great book for the newcomer. While it is not printed in color, it does give a great insight into how WPF works.

Pro WPF in C# 2008 - Matthew Macdonald
This is a great reference book - one that sits on my desk and is constantly referred too. However, I didn't feel is was as newbie friendly as the other two books above. This is the most recently released book (at the time of this posting), and has been updated for VS2008. This is useful, as there are some changes with the versions of WPF. I believe there is a VB.NET version available.

Programming WPF - Chris Sells & Ian Griffiths
Another great book - I wish this was available when I was first learning the framework.

Application = Code + Markup - Charles Petzold
This was the very first WPF I purchased. It is not very newbie friendly, and I wouldn't recommend it for a first-time-wpf'er. The fact that Xaml is not introduced until page 457 makes learning the technology for the real world very difficult. That said, this book is invaluable if you really want to understand how things work at a very deep level (which is also important to get the most of the framework.

The only book I would totally avoid is:

Professional WPF Programming - Chris Andrade et al.
While the content was Ok in this book, I just found the other books to be much clearer and delve to a much deeper level.

Hope this helps! WPF has a steep learning curve, but once you "get it", UI programming can actually become "fun"!

Sams Teach Yourself WPF in 24 Hours.

I'm one of the authors, so my opinion is biased. Our book is structured around building four applications. It's not as in-depth as Nathan's or Petzold's books. Its intent is not to be exhaustive (or a reference), rather it is a means to coming up to speed quickly on WPF. Likewise, to provide a foundation so that you won't feel overwhelmed when you encounter some of the various nooks and crannies in the technology.

I'm currently starting in on "Pro WPF with VB 2008: Windows Presentation Foundation with .NET 3.5 (Paperback)" and so far am pretty happy with it. Good for us VB'ers... :)

MCTS Self-Paced Training Kit - Microsoft .NET 3.5 Windows Presentation Foundation (70-502)

I personally find that I become much more motivated to read and learn about a topic if the learning process culminates with a Microsoft Certification. If you're anything like me, you may find it more rewarding to dive into this certification study guide that just came out a week or two ago.

A new book just came out by notable WPF expert, Pavan Podila (with a little help from Kevin Hoffman). It's all about building controls in WPF and is aptly called:

WPF Control Development Unleashed

If you're going to be building visuals, elements, or controls in WPF, you will want this book on your shelf. Getting to the point where you understand enough of the WPF API and concepts to write a decent control, takes enough time ... this book will ease your journey!

Yes, I highly recommend this one

Most restrictions and tricks with windows forms are common to most programmers. But since .NET 3.0 there is also WPF available, the Windows Presentation Foundation. It is said that you can make "sexy applications" more easy with it and with .NET 3.5 SP1 it got a good speed boost on execution.

But on the other side a lot of things are working different with WPF. I will not say it is more difficult but you have to learn "everything" from scratch.

My question: Is it worth to spend this extra time when you have to create a new GUI and there is no time pressure for the project?

There is a very steep learning curve to WPF, and I recommend you get the obvious books first (Adam Nathan, Sells/Griffiths, and Chris Anderson) and blogs (Josh Smith, etc.). Just be prepared for it, and make sure your project allows you the time to learn WPF.

In addition to learning the technology, spend some time learning the patterns used to construct WPF applications. Model View ViewModel (MVVM) seems to be the one that has gained a great deal of acceptance.

Personally, I think WPF is worth it but be forewarned. Also note that you effectively restrict your users to Windows XP SP2+ and Windows Vista. We've made that decision, but you may have some different requirements.

We are currently rewriting our application in WPF from Windows Forms. Yes, there is a steep learning curve and you have to "re-learn" some things, but it is so worth it. And combined with WCF, we are finding we are writing less code, faster, and more robust than ever before.

Stick with it for a while, read Adam Nathan's book, and check out the ever growing library of third-party controls like those from Telerik and ComponentOne. One negative, in my view, is that the design tool, Expression Blend, is very awkward to use. The latest version is still in beta, but it just doesn't feel right to those of us who have used Visual Studio for years. Yes, it's mainly for designers, but some things you just can't do in Visual Studio.

I've been using Winforms since .NET 1.1 and I want to start learning WPF.

I'm looking for some good resources for a beginner in WPF. What should I read, what tools do I need, and what are the best practices I should follow?

I'd recommend the book Windows Presentation Foundation Unleashed by Adam Nathan

Then I'd recommend you write an application. Like every other dev environment, there are no perfect guidelines. You have to find the ones that make the most sense for your circumstance. The only way to do that is to just start coding.

As for tools, Visual Studio 2008 [Express] is your best bet. Or you might be able to limp along with XamlPad.

I've read and heard from several people that WPF has a pretty steep learning curve (depending on how knowledgeable or experienced you are). Seems like most people can get the demo or starter projects to work, and then find themselves getting stuck for lengths of time on miscellaneous problems. I'm curious what specifically is difficult to learn or understand (layers, SDK, XAML, data binding, etc.) and if you have any suggestions on how to avoid/alleviate some of those difficult topics?

It's going to be one of those 'it depends' answers but all it really depends on is if you're the kind of developer that tries to continually improve your skills. If that's the case then it comes down to a couple of things ultimately.

Buy WPF Unleashed (others books are available but I whole-heatedly recommend this one), work through the examples and in about 2 months or so you'll wonder how you ever got things done without it.

It's not rocket science and there are no paradigm shifting concepts to deal with. In fact, if you are used to keeping a good separation between your logic and presentation it should fit right in.

To get to a level of mastery you're probably looking between 6 and 12 months of playing with it.

Good luck.

I would like to know if there is any way to style a WPF layout grid's cells, rows and columns. I've been trying to find any information and the few mentions I've found have not been that informative.

I would like to style the grid to look like the one in the linked screenshot.

If the actual control does not support it, can I inherit it somehow and do it then? I am quite new to WPF so any help would be very appreciated.

One other thing, I know I can style each and every control within the grid, but it seems like overkill. I would like to have a grid that does it itself.

screenshot

I would recommend using borders for your styling.

You could recreate that layout pretty easily by creating borders for each row and each column and set the rowspans and colspans accordingly.

You will have 5 borders with colspan 2, these borders will take care of your gradient backgrounds for each row and the borders along the top and bottom of each row. Then you will have 2 borders with rowspan 5 these will handle the column borders. Imagine that you are overlaying the borders to form the visual grid effect you are after.

For the header and outer border, just wrap the entire grid with a border and style as needed.

I would recommend storing your styles as resources so you can keep all your styling info in one place.

Take care to learn how the styling works because it is pretty powerful, but there is a learning curve as it is quite different to the way CSS works. I would recommend reading WPF Unleashed if you can.

I have some 5+ years' background in C++/Unix development. I have been trying my hand at C#/.Net/WPF based software development for some time now. I am at a stage where I can write functioning applications fluently, but am not sure how to take my skills to the next level.

So, my question(s) to you all, especially to those who are experienced in C#/.Net/WPF:

  • What are the component skills and knowledge that an expert developer on this platform should have?

  • What technology-specific books would you expect a would-be expert to have read?

  • What other deliberate steps can I take to become really good at application development using C#/.Net/WPF?

Many thanks in advance! I would be especially grateful for comprehensive answers - I'm pretty sure many other developers have similar questions.

Learn how the C# language and .NET runtime work by reading CLR via C#.

I really like WPF in Action and Programming .NET Components is essential reading for any .NET developer.

My team has worked in C# for the past 5 years. Typically, experienced C++ programmers take a week or two to become fully functional in C#. I've even seen some do it almost instantly, after sitting with them one morning, showing them our code, and explaning the basics of the language that differ from C++. But that's not how I recommend you do it.

I recommend you do this:

Read a C# book: My pick would be Programming C# by Jesse Liberty. Important chapters are the language itself and the basics of the .NET framework libraries. The .NET Framework is huge, so you don't have to know everything in detail. You can skip through (or skim) the Windows Forms chapters. Windows Forms is so different from WPF that it won't be useful to you if you are planning on only doing WPF.

alt text

Read a WPF book: The best book I read so far is Windows Presentation Foundation Unleashed by Adam Nathan. WPF has a steep learning curve compared to Windows Forms, even for experienced C#/WinForms programmers. It has a lot of complex elements to understand like XAML, dependency properties, bindings, templates, animation, resources, etc. This book teaches you the basics gradually and is easy to read and understand. And it's in full color!

alt text

Read about the Model-View-ViewModel pattern: I haven't found a good book on that yet, but it's been very important for me to make my WPF applications more simple and manageable. My favorite material to learn about MVVM is this one hour presentation by Jason Dolinger. He builds a WPF application from scratch using no particular pattern, and step by step, migrates it to the MVVM pattern.

I would add unit testing, TDD, and mocking frameworks to your list of things to know.

I have "The Art of Unit Testing" and found it helpful.

I am totally new to WPF and looking for good quickstart documentation to start with. I will buy the book WPF Unleashed from Adam Nathan, but thats more a reference than a quickstart i think.
I just want you to tell me your favorite links and books and maybe demo applications concerning wpf development.

Focus of answers should be on best practices, good readable introductions (i hate the link farms on msdn ;) and comprehensive references.

EDIT: I will try to assemble all suggestions in a short list sorted by type. And please try to give a short reason why you suggest especial that link or that book.

Books:

Blogs:

Links:

Demo Applications:

There is an excellent Hands on Lab for building an Outlook-esque UI using Blend and Visual Studio. It is a bit out of date in terms of Blend 2.5, but it is instrumental in learning how to use WPF and effectively using Blend.

I have experience writing console and network client/server applications in C and C++, but I know next to nothing about using the win32 visual API, MFC, Qt, wxWidgets, etc. Where is a good place to start, and what method should I specialize in, so as to be future ready and robust?

This is a rather broad question, as programming GUI applications in Windows can be done in so many ways.

There are two main parts to developing any GUI app: the language and the API/framework. Considering you're interested in learning to build Windows GUI apps, the language isn't really a point of focus for you. Hence, you should pick a language you already know and work with a framework or API that can be harnessed by your chosen language.

If you want to use C you're pretty much restricted to dealing with the Win32 API yourself, in which case reading Petzold or Richter would be great places to start. The Win32 API can be quite daunting, but it's well worth the effort to learn (imho). There are plenty of tutorials on Win32 on the web, and there's always MSDN, with a complete reference/guide to the Win32 API. Make sure you cover not just the API, but other areas such as resources/dialogs as they are building blocks for your Win32 application.

If you want to use C++ you have all of the options that you have when using C plus a few others. I'd recommend going with the Win32 API directly, and then moving on to a known framework such as MFC, Qt, wxWindows or GTK so that you can spend less time working with boilerplate code and instead focus on writing your application logic. The last 3 options I just listed have the added benefit of being cross-platform, so you don't have to worry too much about platform-specific issues. Given that you said you want to work with Windows, I'll assume you're keen to focus on that rather than cross-platform -- so go with MFC, but spend some time with the Win32 API first to get familiar with some of the concepts.

When dealing with MFC and the Win32 API, it's a good idea to try and get a solid understanding of the terminology prior to writing code. For example, you need to understand what the message pump is, and how it works. You need to know about concepts such as "owner-drawn controls", and subclassing. When you understand these things (and more), you'll find it easier to work with MFC because it uses similar terminology in its class interfaces (eg. you need to know what "translate messages" means before you can understand how and when to use PreTranslateMessage).

You could also use Managed C++ to write .NET GUI applications, but I've read in a few places that Managed C++ wasn't really intended to be used in this manner. Instead it should be used as a gateway between native/unmanaged code and managed code. If you're using .NET it's best to use a .NET language such as VB.NET or C# to build your GUIs.

So if you are going to use .NET, you currently have the choice of the WinForms library, or WPF. I personally feel that you'd be wasting time learning to build WinForms applications given that WPF is designed to replace it. Over time WPF will become more prevelant and Winforms will most likely die off. WPF has a much richer API set, and doesn't suffer from many of the limitations that Winforms does. If you do choose this route, however, you'll no doubt have to learn XAML, which is a markup language that drives WPF applications. This technology is coming of age, and there are many great places to learn about it. First, there are sites such as LearnWPF, and DrWPF which have some really great articles. Secondly, there are plenty of quality books on the topic.

So, to sum up, once you've picked your language and tech, the path is actually quite easy. Just pick up a book or two, read some blogs, get into some code samples.. and most importantly ... write code. Keep writing, keep making mistakes, and keep learning from them.

As a final note...

In other words, Silverlight. If you don't want to go the MS route you might give Adobe's Flash/Flex a look see. Both Silverlight and Flash/Flex build RIA's. Which I think is where we are headed. They days of Office like apps are numbered

I don't agree at all. Silverlight is not the same as WPF. Silverlight is web-specific, and only has a subset of WPF's features. Given that the question asks for Windows GUI apps, Flash/Flex Rich Internet Apps are not really a fitting suggestion. I also don't agree that the days of Rich Client Applications (such as office) are numbered at all.

I hope that helps. Good luck :)

I'am more a sysadmin and a webmaster than a developer, but sometime I develop, including C# principally using Winform (and optionally GTK+).

I've started few weeks ago a WPF project, and it seem really powerful, but at start I feel like a hen who found a knife! There is so many difference!

stackoverflow abounds about topic like that, and I've read carefully some who are similar like:

But, when somebody start with WPF from Winform, What are the differences to which he must pay attention?

[EDIT]

  • What about some advices/links for LINQ with WPF?
  • What about some advices/links WPF Navigation?

Thank you all, but all this is a bit diffuse, so I made a resources compilation and add some things by my own, please tell me what you think (or improve, I make it Community Wiki)

Strangely no one has talked about LINQ which seemed to be a central element of this technology.

Another thing that seems important to know given the time I lost, is not to use the WPF navigation system that doesn't seems to work properly from numerous sources I've read. So, it seem important to use a navigation framework, like Magellan.

And the routed event system seem to be an important point to look at in WPF, if somebody have some interesting resources about it, please add to this post.

RTFM

Software

Blog posts

Videos

The Code Project

Books:

Other Stack Overflow topics

WPF is completely different from other systems.

I have a few years of WinForms, Win32 and web programming experience, and I believe my web programming experience helped the most.

As for books, "Windows Presentation Foundation Unleashed" from Adam Nathan, Sams Publishing has helped me tremendously.

to getting started with WPF a design pattern Model View ViewModel (MVVM) would be important to know. also I would recommend Adam Nathan WPF4 book. I think it's great one!

I have a Page page in a Frame frame, with frame.DataContext = "foo".

  • (page.Parent as Frame).DataContext is "foo". ok
  • BindingExpression for page.DataContext is null (also forced with ClearValue). ok
  • page.DataContext is null. but I expected "foo"!

Why isn't the DataContext inherited? As far as I understand the Frame sandboxes the content. But I couldn't find any documentation of this behavior - can anyone point me to a place where this is mentioned?

To answer your question about documentation of this behavior: It's not Microsoft documentation, but I have a couple of WPF books that both mention this.

"Essential Windows Presentation Foundation" says: (pp. 160-161)

There are two interesting models for hosting navigable content: isolated hosting and integrated hosting.

With isolated hosting the content is not trusted and is run in a completely isolated (sandboxed) environment. This is how WPF content is hosted when running in the system Web browser as a XAML Browser Application. For navigation to another application or HTML content, this isolated hosting model is supported with a Frame object.

Integrated hosting, in which we want the content to behave as part of our application, is not supported at all in the system. When Frame navigates to content within the application, we get an odd hybrid of isolated and integrated behavior. Frame isolates its content from its style (and its parent's style), but not from the application's style. Events don't bubble from the content in Frame; however, the objects are accessible from the Content property (meaning that they aren't isolated in a security sense).

For all these reasons, Frame is most useful when we're working with external content, but it can be carefully used for application content.

That's all it has to say -- nothing about property inheritance.

"Windows Presentation Foundation Unleashed says (p. 95):

The Frame control holds arbitrary content, just like all other content controls, but it isolates the content from the rest of the UI. For example, properties that would normally be inherited down the element tree stop when they reach the Frame.

I am having trouble finding good guides for WPF.
I have experience in C# and .NET but I don't know anything about WPF except for the regular marketing-ish description of the technology as a whole.
Can anyone point me to a good beginner's tutorial/guide on WPF.

I would buy a book - the Adam Nathan WPF book is good.

http://www.amazon.com/Windows-Presentation-Foundation-Unleashed-WPF/dp/0672328917

Programming WPF by Chris Sells and Ian Griffiths is an excellent way to learn WPF. 5 star rated on Amazon with 50+ reviews. http://www.amazon.com/Programming-WPF-Chris-Sells/dp/0596510373

Ok, in terms of reading material, this is the pick of the books out there: Windows Presentation Foundation Unleashed.

For blogs, there are a lot of blogs and articles on WindowsClient.net, and there's an excellent blog all about data binding in WPF by Beatriz Costa. Also take a look at LearnWPF.com and Ask Dr. WPF.

Keeping in mind what CannibalSmith once said - "All the answers are saying "WPF is different". That's a huge understatement. You not only have to learn lots of new stuff - you must forget everything you've learned from Forms. It's a completely new way of doing UI."

.. and having many years of experience with visual Windows desktop applications development (VB6, Borland C++ Builder VCL, WinForms) (which is hard to forget), how do I quickly move to developing to say well-formed WPF applications with Visual Studio?

I don't need boozy-woozy graphics to give my app look and feel of a Hollywood blockbuster or a million dollar pyjamas. I always loved tidiness of standard Windows common controls and UI design guidelines, end even more I enjoyed them under Vista Glass Aero Graphite sauce.

I am perfectly satisfied with WinForms but I want to my applications to be built of the most efficient and up-to-date standard technologies and architectured according to the most efficient and flexible patterns of today and tomorrow, leveraging interface-based integration and functionality reuse and to take all advantages of modern hardware and APIs to maximize performance, usability, reliability, maintainability, extensibility, etc.

I very much like the idea of separating view, logic and data, letting a view to take all advantages of the platform (may it run as a web browser applet on a thin client or as a desktop application on a PC with a latest GPU), letting logic be reused, parallelized and seamlessly evolve, storing data in a well structured format in a right place.

But... while moving from VB6 to Borland C++ Builder was very easy (no books/tutorials needed to turn it on and start working) (assuming I already knew C++), moving from BCB to WinForms was the same seamless, it does not seem any obvious to me how to do with WPF.

So how do I best convert myself from a WinForms developer into a right-way thinking and doing WPF developer?

My problem is that I need to add a lot of items to a ListBox in WPF. In WinForms you'd just use the BeginUpdate(); method, add everything, and finally use the EndUpdate(); method.

So, how would I stop the drawing in a WPF listbox until every item is added and then draw everything in one go?

It sounds like you might be programatically adding the items to your list box one-by-one. A better approach would be to store the items you want to display in a model, and bind the model to the list box's data context. This will allow WPF take care of the rendering updates.

If you add snippets of your XAML and code to the question (to show us what you're currently doing), we might be able to provide a better answer.

EDIT: Added a very simple example.

Here's an example that binds a view model to the main window (the view) and then the XAML declares that the ListBox's data is bound to the view model's Numbers property.

MainViewModel.cs

public class MainViewModel
{
    public IEnumerable<int> Numbers
    {
        get { return Enumerable.Range(1, 1000); }
    }
}

MainWindow.xaml

<Window
  x:Class="WpfApplication1.MainWindow"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Height="350"
  Width="525"
  >
  <ListBox ItemsSource="{Binding Numbers}"/>
</Window>

MainWindow.xaml.cs

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        DataContext = new MainViewModel();
    }
}

If you're just getting started with WPF, I can highly recommend Windows Presentation Foundation Unleashed by Adam Nathan. It's a great book and it's in colour to boot. Reading other books after this is like going back to Notepad after using Visual Studio.

For more on this Model-View-ViewModel stuff, check out Josh Smith's Advanced MVVM book.

I've been developing Winforms applications in C# for a few years now and have been interested in moving future development toward WPF, mainly because of the positive things I've been hearing about it. But, I'm wondering what sort of hurdles others have had to overcome as they migrated to WPF. Was there a significant hit to your productivity or any particular issues which you found challenging?

In my admittedly limited experience with WPF, the bigger hurdles include a complete overhaul of my mental model for how UIs are built and the new terminology that needs to be learned as a result of that. It may be that others have an easier time adjusting to the model, though. I can see how someone coming from best practices in the web world would find the transition much more natural.

There was definitely a significant hit to my productivity (so significant that I'm not yet comfortable with the idea of going to my employer and saying "let me do this with WPF instead of Winforms"). I don't think that I'll never get there, but I need to develop some additional comfort with the technology through practice in my personal time.

I didn't run into any particular issues that I found to be more challenging than any others. I believe Adam Nathan's WPF Unleashed was mentioned elsewhere, and that's definitely a worthwhile read. I've also heard good things about Charles Petzold's book, though I can't personally vouch for it.

I Adobe Air completly JavaScript? Can't I use a .NET language like VB.NET or C#.NET?

Thanks

As the official answer states, Adobe Air does not support .Net languages. If you are looking for something similar for Windows desktop programming that does support .Net I would suggest WPF. The WPF Unleashed book is pretty good if you want to come up to speed quickly.

WPF is build into .Net 3.0 and 3.5, and runs on WinXP SP2, Vista, and Win2k3 and Win2k8 Servers.

Note: This was written when another answer was marked as the accepted "official" answer.

I'd like to study up on the latest technologies for writing Windows desktop apps. My last experience was with VC++ 6 using MFC. The landscape seems more complex these days, I'm not sure if I should learn .NET, don't really know what Windows forms, WPF are etc. All I want to do is be able to write some simple Windows GUI apps, probably using & learning C# along the way.

Any recommendations on books to read etc?

Also, is the free version of VC2008 good enough for writing small apps?

I would go with .NET and WPF. WinForms is still available, but is really a legacy branch of .NET at this point, and not worth learning if you are starting from scratch. WPF offers a lot of good features, and is pretty use to get up and running with.

I found "Windows Presentation Foundation Unleashed" a good introduction to WPF. It explained the foundational concepts well and wasn't just one of those 2,000 page tutorials full of screen shots.

I recommend Head First C#. If you've programmed in C++ before, you should be up to speed fairly quickly.

alt text

I want to implement a rather complex CurveEditor that has to support the usual requirements like:

  • freely scalable and moveable axis
  • different interpolation types per curve point (Linear, Cubic, Spline)
  • Tangents (joined and broken)
  • Selecting one or several points to edit (move, scale, delete) via Fence or Click
  • Only show handles and highlights for selected curve points

sample illustration of the CurveEditorComponent

I don't want to manipulate actual WPF curves but an existing model with key/value/tangents sets and sample the precise shape of the curve from our implementation.

I already gathered some experience on implementing custom UserControls and Templates. But I want to make sure, I don't miss any apparent solution. I planned to have this general XAML-tree:

  • CurveEditor - Window holding all content
    • MainThumb : Enable dragging and scaling the editor range
    • XAxis : UserControl rending some scale on the left side
    • YAxis : UserControl rending some scale on the bottom
    • Curves : Canvas holding the curves
      • Curve : UserControl for a single curve
        • CurveName - Label of the curve
        • CurveLine - DrawingVisual that will render the actual curve by sampling the internal implementation of the spline function.
        • CurveEditPoints - Canvas that holds all edit points
          • CurveEditPoint - UserControl for a single edit point
            • LeftTangent - UserControl for the left tangent handle
              • LeftTangentThumb - For modifying the handle
            • RightTangent - UserControl for the right tangent handle
              • RightTangentThumb - For modifying the handle
          • CurvePointCenter - Visualisation of the actual point, select state and interpolation type.
            • CurvePointThumb - Thumb to select and drag point around

I know, this is quite a complex question and I am not asking for an actual implementation. I am interested in the following questions:

  1. Can you recommend any tutorials or books that might help me (I already got Illustrated WPF, WPF Control Development Unleashed, and a couple of other)
  2. Should minor elements like the Tangents be individual UserControls?
  3. What container is best suited for hosting the individual "Curves", "EditPoints" and "Tangents". Right now, I use Canvas and Canvas.SetLeft/SetTop to position the children, but that feels "strange".
  4. Should I use "Shapes" like Path or DrawingVisual-Classes to implement actual representation. Path is straight forward, but I am concerned about performance with hundreds of CurvePoints.
  5. Should I use Transforms to rotate the tangents or is just fine to do some triangulation math in the code behind files?
  6. Does the structure roughly make sense, or do you suggest a completely different approach?
  1. you seem to have the right tools at hand, WPF Unleashed is excellent, but I guess you have that one already.

  2. make individual UserControls in one of these cases:

    • you are using the same xaml all over the place (DRY)
    • you xaml file gets too big (get some components out)
    • you need to inherit from some class
  3. this depends on how much codebehind you want.
    you can, as you suggested in your comment, use an ItemsControl as a container for wherever you need selection between multiple items. so this could also be done on the level of Curves, not just on the level of points on the curve. Depending on how you want to handle drawing of the actual lines and curves you can even have an ItemsControl for those. (on a side note: you will not have virtualization out of the box though, as your items won't have a constant height)

  4. Path is OK with hundreds of CurvePoints. If you have 10.000, I'd say you could get problems.
  5. can't imagine how a transform should be used here, maybe inside an Adorner.
  6. your structure looks good. you will be able to implement all of this. I will suggest though how I would do it:

first of all use MVVM.

  • CurveEditor
    ListBox(Panel=Canvas)(ItemsSource=Curves)(ItemTemplate=CurveControl)

  • CurveControl

    • Canvas(Background=Transparent) <= I'm not sure if standard is white, but you don't want to overlap other Curves...
      • CurveName
      • ListBox(Panel=Canvas(Background=Transparent))(ItemsSource=CurveParts)
      • ListBox(Panel=Canvas(Background=Transparent))(ItemsSource=CurvePoints)(ItemTemplate=>EditPointControl)
  • EditPointControl

    • Canvas
      • Thumb(Template = Ellipse) (Name=CenterHandle) (with some Visualstates for Selection and hiding of Tangents)
      • Thumb(Template = Ellipse) (Name=LeftHandle)
      • Thumb(Template = Ellipse) (Name=RightHandle)
      • Line (Binding X/Y to Centerpoint and LeftHandlePoint)
      • Line (Binding X/Y to Centerpoint and RightHandlePoint)

I have stated to set ItemTemplate for the ListBox. You can however style the listbox however you want (I think the standard style includes a border, you might want to remove that or set bordersize=0) and set instead of ItemTemplate the ItemContainerStyle and bind to IsSelected so you have control over IsSelected from your ViewModel (look here for what I mean).

So the viewmodel looks like this:

- CurveEditorViewModel
    - ObservableCollection<CurveViewModel> Curves


- CurveViewModel
    - string Label
    - (Point LabelPlacement)
    - bool IsSelected
    - ObservableCollection<CurvePointViewModel> CurvePoints
    - ObservableCollection<CurvePartViewModel> CurveParts


- CurvePointViewModel
    - Point Position
    - bool IsSelected
    - Point LeftHandle
    - Point RightHandle

- CurvePartViewModel
    - CurvePointViewModel StartPoint
    - CurvePointViewModel EndPoint
    - Path CurvePath

in here you can subscribe to CurvePointViewModel's PropertyChanged and recalculate the Path you're exposing.

I'd probably improve on it as I go but that'd be my first guess.

There are some details you might want to watch out for. eg: the style for the thumbs might be a visible circle in the middle and an invisible bigger one around that with background=transparent. that way you can have your visible circle small, but have the user use the tumb in an area around the small circle.

EDIT:

here is an Example for the Thumb:

        <Thumb Width="8" Height="8" Cursor="Hand" Margin="-4">
            <Thumb.Template>
                <ControlTemplate TargetType="Thumb">
                    <Grid>
                        <Ellipse Fill="Transparent" Margin="-6"/>
                        <Ellipse Stroke="Red" StrokeThickness="2"/>
                    </Grid>
                </ControlTemplate>
            </Thumb.Template>
        </Thumb>

as you want to position this at a specific point on a canvas setting the Margin to minus half the width and height will place the center of the circle on that point. Furthermore, having that inner ellipse with a transparent fill and Margin of -6 you will get a 6px bigger radius around the inner (smaller) circle where you can drag the thumb.

I'm very new to programming, and I'd like to write a Windows Application. So far I've read Teach Yourself C in 24 Hours, what should I do (tutorial to read) next to accomplish my goal? Thanks

Read this book, Learn to Program with C#.

Then, make small projects in WPF; the best WPF book is Windows Presentation Foundation Unleashed; try that after reading the C# / beginning-programming book.

C#, the .NET Framework and WPF were created to move beyond the C Win32 API, to make it easier to create Windows applications.

If you want to make a standard Windows application, follow that path.

While I won't say you've wasted your time learning some C, I'm guessing it's not where you're going to end up either.

If you really want to get rolling, without too much trouble, I'd highly suggest getting:

This should get you pretty much exactly what you want. You'll have everything you need, and Petzold starts you out very simply, and ramps you up to making interesting apps without losing you.

(You may wonder why I, and many other people are directing you to C# or other languages after you specifically said that you've already read and learned about C. This is because programming in windows using the old Win32 API is much more tedious. It is easy to quickly become overwhelmed by the sheer amount of extra chaff that has to go into it.)

Recently I just got assigned a project to develop a web application/site that uses the full capacity of Silverlight 3.0. I am a beginner in web development and so far I am more of a software engineer guy rather than messing stuff with web development.

However, I am really excited for this new experience as I feel that I can explore more. So I just started learning the .NET Framework, C#, and a bit of ASP.NET the last 3 days.

Just to let you know my background in programming, I have programmed in Java and C for 3 years as of now so I am quite experienced with it. Any suggestions that you can give me?

The project will start in 1.5 month from now so I got some stuff to catch up with. I think my approach first is to understand the concept of .NET and ASP.NET first and then in the end learn Silverlight. I believe C# wouldn't be too hard, looking at my background that I have.

Can you recommend some good books and other resources that would help me out in my study process?

If you have a good amount of Java experience, C# is a breeze. It's the same idea with different capabilities and implementation. So, your collections classes have different names, generics looks slightly different, and your threading stuff is done a little differently. Think of the stuff you do often and the Java objects/frameworks/libraries you use often and just find the .Net equivalents.

I don't believe anything like LINQ exists in Java, so that's a really cool aspect of .Net programming to take a look at. This book has a great quick introduction to LINQ concepts and the rest can be used as a reference.

Silverlight/XAML/WPF is pretty simple, but it comes with a really big framework and a ton of things to learn because it's so flexible. http://silverlight.net/ and http://windowsclient.net/learn/ have some great videos for you to pick a feature or two to use as a basis to get up to speed with a number of concepts of silverlight, c#, .net etc. Sounds like you don't have the time to take down several books, so these videos should be pretty cool, and there's tons to choose from.

As far as what specifically to learn about Silverlight, I'd say the binding is probably the coolest feature. And, take a look at animations, because that's a really cool aspect that is fairly easy to implement.

Here's a PDF WPF binding expression cheat sheet to use as a reference. And, here is a pretty simple example of doing Silverlight animations in C#.

As a Java/C programmer, probably the biggest challenge will be getting your head around and into the way Silverlight (and WPF) work. If you approach them as if it was a traditional UI toolkit such as the Win32 API, you are going to come unstuck.

I found WPF Unleashed good for getting into WPF (after initially struggling with the concepts). Hopefully Silverlight2 Unleashed will be as good, although I havent read it.

The learning curve is painful, however once things "click" you wont go back.

There are some projects that could use WPF at work, for the sake of adopting new technologies.

But the problem is, I can't jump start WPF easily. I recognize the learning curve is steeper than Winforms. Though even with Winforms one can start doing UIs and programmatically customize them in a day.

So the problem is:

  1. I don't have any resource to quickly learn the fundamentals of WPF at work. I can't read a book from cover to cover before I do the simplest of things.

  2. Most tutorials on the net, just does things that excludes the fundamentals. i.e. they post partial xaml code I can't even put into my xaml code correctly (VS highlights them in red).

  3. I can't justify using WPF over Winforms where there is no significant gain for prety much all projects I can think of. And the learning curve just makes things worse.

So I can't suggest my manager to use this tech over the traditional Winforms, but I want to.

Is there a guide or a tutorial on the net, or a video that explains the fundamentals of WPF so I can explore everything else on my own, except the more complicated tasks?

I am brand new in the world of Wpf, and am thinking it's time to get into it for my next project.

I'm a hardcore Winforms guy. Many of my projects perform tons of custom drawing - for example drawing a virtual baseball strike zone and then drawing icons to represent pitches thrown by a pitcher or seen by a batter. The pitches are interactive - the user can select one or multiple pitches (click, shift-click, rectangle drag) and then play video of the selected pitches.

I also have applications where I draw custom objects and then allow the user to drag them around and place them on a blank canvas.

I am trying to learn how one would do these types of things in the Wpf world. I got my first "hello world" graphic program working today, where I overrode ArrangeOverride and drew some lines on a blank window. But I've been reading about UIElement classes and Adorners and want to make sure I'm doing things "the right way". Should all my pitches be their own UIElements, for example?

I'm wondering if someone can guide me to some sample code or a book or article to get me started. If I could see "the right way" to create a custom drawn object (of any complexity, a simple rectangle would be fine), have the user select it (highlighting it somehow to show that it's selected) and then have the user drag it around the Wpf window, I would be well on my way.

I also come from a WinForms background and the best book I've found is "Windows Presentation Foundation Unleashed" by Adam Nathan.

Amazon: http://www.amazon.com/Windows-Presentation-Foundation-Unleashed-WPF/dp/0672328917

It's a very XAML focused book. I feel is very important for a WinForms guy because you have to get out of the mindset that code controls your UI. XAML is kind in the WPF world and you need to get into the habbit of starting in XAML vs. code.

I think I have got some grasp over basic WPF fundaes.

Now I want to go deep. However, apart from understanding how the classes work under the hood, I would like to learn practical aspects of WPF; that is, how to use it in real life projects.

I have seen a number of such books for Web Frameworks and languages such as Django, PHP etc, but none for WPF or for that matter, Winforms. All books of WPF/Winforms just include snippets, for that particular section/chapter.

I saw this question: http://stackoverflow.com/questions/720727/practical-silverlight-wpf-books, but it has more silverlight taste. I want for WPF.

I think reading blogs by WPF disciples and others is a good option, but I was thinking more of a systematic study.

So my question in nutshell is, what is the best systematic way to learn practical WPF programming for an advanced beginner?

Thanks!

I started with "Essential Windows Presentation Foundation", because it starts you out building running applications from the beginning. It starts with Window and goes from there. The first working WPF code sample is in Chapter 1, starting on page 17.

Then I read "Windows Presentation Foundation Unleashed", which goes much deeper overall, but starts with theory. IMO, it wouldn't have been a good book to start with -- far too much dry theory, and no chance to try it out until they finally get to Application and Window in Chapter 7; you don't know enough to write a running WPF app until page 198. So I wouldn't recommend this as the first WPF book you read. But for someone who already knows the basics, it's terrific.

After that:

  1. Start writing hobby apps. I've been teaching myself WPF by writing a couple of video games and a dependency-tracking task-list app. Haven't finished any of them yet, but I've learned loads.
  2. Teach someone else what you know. This is a fabulous way to find out where the gaps in your knowledge are, and to help cement what you already do know. I've been doing WPF Lunch and Learns for the other devs in my department. One day we sat down with a blank Visual Studio project and made up a movie-database app over lunch.
  3. Whenever you find something you don't know how to do yet, search Google and/or StackOverflow. If you don't find the answer, ask it here.

I would like to create a level editor for Silverlight with XAML. What resources would be useful for research before starting such a project?

Here is some information to clarify. I made 1 silverlight game and released it so far. The I would like to have an overhead style action game. The map would be much larger than the current viewable space.

WPF has a steep learning curve, don't get dis-heartened it's brilliant, but it has so many nooks and corners that it'll take a while to get comfortable. For a start there's a really good blogging community at WPFDisciples all of these are worth reading. Codeplex has some good libaries for 3D, physics engines etc and reverse engineering others code is a good way to learn.

A couple of good books are Windows Presentation Foundation Unleashed and Petzold's Applications = code + markup is one of the few books/places that doesn't preach that everything has to be done in Xaml

An area that takes some getting used to is binding, lots of stuff out there but it can be complex, and it's a impossible to debug until you have the magic knowledge. Binding in WPF isn't just about data, it's about linking all UI elements and behaviours together - it's really important.

Finally you have a choice between Silverlight and WPF, they're not the same. Although Silverlight is a good sub set of WPF, there are certain things you just can't do.

Finally Finally if you have a graphic design, artist background try using Blend, not VS it's a much better tool for those who are visually aware.

Recently, I've started working with WPF, and I'm asking a lot of what I think are basic questions about databinding. I don't 'get' it yet; why one thing works and not another (for seemingly voodoo reasons), how I accomplish what I want to do, and what everything means precisely.

There's lots of tutorials out there that go over the simple basics, but I can't find any that cover things similar to the more complicated examples that I'm trying to do. I don't want to create lots of toy apps, I want to understand what on earth is going on and what everything means. Where can I learn this?

Not knowing where you've already looked makes it a bit harder to recommend anything, but I started with two items on The Code Project, 1 from Josh Smith and 1 from Sacha Barber. From there, I read a lot of Josh's blog posts, and eventually bought WPF Unleashed.

Possible Duplicate:
What WPF books would you recommend?

GUI's written using WPF seem to be closer to a Web 2.0 feel than older Winforms development has been; do you know of any good quality references online or books which give a general overview of how to design nice WPF applications?

I saw this StackOverflow question where some GUI design books are mentioned, but am interested in information specifically for WPF.

Is WPF & SilverLight Design worth learning

Thanks!

I found WPF Unleashed to be very UI-centric and WPF Control Development to be like the next step (very advanced GUI stuff). The huge WPF book on Apress is great for in-depth coverage on the topic, but the red books on Sams would probably be better for what you're looking to get out of them.

WPF Unleashed on Amazon

WPF Control Development Unleashed on Amazon

I'm aware that in WPF you want to keep the sizes of controls as flexible as possible so that they can flow and expand depending on their context (like in CSS).

But most of the code examples I come across are hard-coding sizes like the heights in this example:

<Grid.ColumnDefinitions>
    <ColumnDefinition Width="0.5*"/>
    <ColumnDefinition Width="0.5*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
    <RowDefinition Height="31"/>
    <RowDefinition Height="31"/>
    <RowDefinition Height="31"/>
</Grid.RowDefinitions>

Isn't assigning a height of "31" to each row a bad practice that should not be emulated? Or is there a reason for this? Or could it be that authors create these examples in design view and just don't clean up the hard coded heights.

Does anyone have any best practices regarding element sizing (especially with respect to using the * syntax) that people starting out with XAML can follow to develop good habits from the beginning?

Generally speaking, it's a best practice to use dinamic sizes within XAML because as you say the concept of WPF is to be indipendent from fixed dimensions. In your particular example, i don't know if it's wanted from the writer, remember that there are still some cases involving hardcoded values (maybe a custom menu bar or a panel you want to keep consistent in it's size). The notation "2*" means that the value will be twice the value of other columns and thus, using the star notation in each column is not very usefull.

If you're looking for some examples, i can address you to these two sites (but if you search on google for "WPF star size" or something like that you'll find others). Plus, if you're looking for a very good book about WPF, I can surely point you to Windows Presentation Foundation by Adam Nathan. It's one of my favourite, it's well written, full of coloured examples and covers every single aspect of WPF.

I'm using WPF within Visual Studio 2008. I have a simple WPF UserControl with the following code:

  public partial class UserControl1 : UserControl
  {
    public UserControl1()
    {
      InitializeComponent();
      Composite = new Composite();
    }

    protected override void OnRender(DrawingContext drawingContext)
    {
      //LayoutRoot is name of default Grid instance
      if (!LayoutRoot.Children.Contains(Composite))
      {
        LayoutRoot.Children.Add(Composite);
      }
    }

    public Composite Composite
    {
      get;
      set;
    }
  }

  public class Composite : ContentControl
  {
    protected override void OnRender(DrawingContext drawingContext)
    {
      drawingContext.DrawRectangle(new SolidColorBrush(Color), new Pen(Brushes.Black, 1.0), new Rect(RenderSize));
    }

    public Color Color
    {
      get;
      set;
    }
  }

I then use this UserControl in a WPF application, the XAML of the page looking like this:

<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:test="clr-namespace:WpfControlLibrary1;assembly=WpfControlLibrary1"
    Title="Window1" Height="500" Width="700" Background="AliceBlue">
  <test:UserControl1 Name="uControl1">
    <test:UserControl1.Composite>
      <test:Composite Color="Green"/>
    </test:UserControl1.Composite>
  </test:UserControl1>
</Window>

My question is: what code do I have to add to the above so that by changing "Composite Color" to something other than Green and hitting the return button, the UserControl automatically refreshes? The behaviour I'm looking for is what happens when you change the Background of Window1 to a color other than AliceBlue and hit return.

When I run the code the correct color is seen, the problem is with the refresh at designtime via XAML.

Many thanks for any pointers which help me understand what is going on here!

You are going about this in a very strange manner (reminiscent of an MFC control); take some time and read through the first half or so of WPF Unleashed (http://www.amazon.com/Windows-Presentation-Foundation-Unleashed-WPF/dp/0672328917/ref=sr_1_1?ie=UTF8&s=books&qid=1243491021&sr=8-1), it's enjoyable to read and everything will make much more sense.

I need to build a wpf application with some animations, what do you recommend me to use (sample applications, books tutorials) that can benefit me very fast taking into consideration I have a 6 years experience in DotNet apps.

Thanks

I've just started WPF myself, and I can highly recommend Adam Nathan's book: 'WPF Unleashed'. http://www.amazon.com/Windows-Presentation-Foundation-Unleashed-WPF/dp/0672328917 . It has a friendly style with lots of colour illustrations. It also seeks to teach by example. I would also suggest you download Vertigo's Family.Show and 'dig around under the bonnet'. This is a teaching application that uses every trick in the WPF book it can: styles, templates and the suchlike. Get it from http://www.vertigo.com/familyshow.aspx

Possible Duplicates:
Latest C# and .NET books
Learning C# and Windows Forms, yet another book thread

I already know C#, but now I want to go into forms programming. Are there any good books and tutorials for learning Windows Forms programming?

For Windows Forms I would recommend Windows Forms Programming by Chris Sells

If you decide to go with WPF I would recommend Windows Presentation Foundation Unleashed

I am currently working in C# with wpf, I don't know about graphics, I want to learn about GDI and graphics from scratch, Can anyone help me by providing some basic knowledge or material?

Can anyone tell me to write very first program using Gdi?

If you want to learn about WPF I really suggest "Windows Presentation Foundation Unleashed" http://www.amazon.com/Windows-Presentation-Foundation-Unleashed-WPF/dp/0672328917

Also check out this video from the PDC - Mastering WPF Graphics and beyond: http://microsoftpdc.com/Sessions/CL31

And if you still want to check out GDI you should read this book http://www.amazon.com/NET-Game-Programming-DirectX-9-0/dp/1590590511/ref=sr_1_1?ie=UTF8&s=books&qid=1259061198&sr=1-1

It starts out with GDI+ basics and then moves on to DirectX. Even though it's written for VB.NET you'll get a great deal out of it as a c# developer as well. It helped me back in the days and writing the games in the book is just downright fun :p

(Hint: There is a huge performance issue with the first example in the book, try to solve it, it'll help you understand things even better).

I've been constructing a card game and want to use a good UI framework for my client.

I was leaning towards WPF, since I have VS2010 and good experience with C#, but I'm having doubts about it, since it isn't quite tailored towards games.

I'd like to have something that allows me to do nice (but simple) animations for typical card actions, like drawing/discarding/playing etc. I know WPF has better support for animations that WinForms, but will it be enough for a game like this?

WPF is certainly capable for something like this. In fact, Adam Nathan has an example in his earlier WPF book, "Windows Presentation Foundation Unleashed."

There is a .NET 4.0 version, but I haven't actually seen it. However, the earlier version of the book was quite well done IMHO.

<MenuItem x:Name="newProjectButton" Click="OnNewProjectButton_Click" Header="_New Project">
</MenuItem>

I want to call OnNewProjectButton_Click whenever Alt+N is pressed. The code above doesn't work, unfortunately, because the handler is called only if the menu is expanded (i.e. has focus).

You see to set the InputGestureText on the menu item

<MenuItem Header="Paste" 
 ToolTip="Paste the selected text to text box" 
 InputGestureText="Ctrl+V" />

But unlike WinForms the "The application must handle the user's input to carry out the action".

So consider using the WPF commands as they do this for you automatically. I found that Windows Presentation Foundation Unleashed covers this well.

Where can I start learning Windows Form designing?

For example: Microsoft Zune player, Buttons, Forms and etc.

I'm developing in C#.

Thank you all,

Amit

If I were going to try and write something like the Zune software I would start with WPF rather than Windows Forms. Check out some of the WPF experiences by thirteen23 for good examples of "experience-driven" applications.

You can start learning more about WPF on MSDN or by reading WPF Unleashed.