views:

259

answers:

2

Is xaml in WPF equivalent of .Designer.cs in Windows Forms apps?

Does it just provide compile-time state for the UI?

I am not sure but it looks like you can do things programmatically with xaml at run-time.

If I have a basic UI state where everything is added at run-time, then should I be looking outside the xaml stuff?

+4  A: 

It's probably safe to look at XAML that way - although it's not entirely accurate. The XAML is compiled into BAML, and parsed at runtime - where the Windows Forms designer.cs file is just another C# file built by the designer. XAML is never directly translated into C#.

You can do everything done in XAML via code, though. Charles Petzold's WPF book actually takes this approach. It builds entire WPF applications in code before he ever introduces XAML.

Reed Copsey
Thanks Reed. Then is there a reason to build stuff using XAML directly? I thought only if you need to set the initial UI, you should use XAML for it. Also you think Petzold's book is the best wpf book?
Joan Venge
I actually don't really care for Petzold's book. He does everything code first, which I understand, but think makes it hard to learn. I prefer this book: http://www.apress.com/book/view/1590599551 - XAML has a lot of advantages over code - it helps keep good separation of concerns (esp. if you're using MVVM), keeps the UI clean, etc. You can do pretty amazing things with WPF databinding - even making things in XAML with almost no code that seems completely dynamic. It's easier to keep the UI design and code design separate, flexible, concise, and clean using XAML.
Reed Copsey
Thanks Reed, I appreciate your insight.
Joan Venge
A: 

In addition to Reed's input, I should mention that:

  • XAML uses XML syntax to define UI, but Form does not.
  • In XAML, it is much easier to separate UI from the logic by using code-behind-design. As UI is only XML, and they can be designed totally independent of any code-behind changes.
  • Minor changes like Button where you can set Content instead of Text, so you can set anything whereas it could be only text.
  • Data Binding and Dependency properties are way easier and better in WPF comapring to Windows.Form
  • Very easy and cool way to handle your design, as you can find there are many cool examples on the net.
  • You can use tools such as Snoop to visualize your 3D design, and can inspect and verify all your controls and events by selecting the UI. You can see what events are handled or not. This is a very cool tool, and you can find similar ones.
paradisonoir