Live Blogging VSLive! Austin – Day 1
Today, VSLive! Austin begins with a session by Billy Hollis entitled “Maximizing WPF & Silverlight”. I’ll be updating this post throughout the day with interesting tidbits from the presentation. The problem is that there is no power in the room, so I can only run for so long before I need a recharge. If I have any complaints about VSLive!, this is it: know your audience – we need power!
I’ve been to several of Billy’s presentations in the past, and he is a real GUI Guru, so I look forward to today’s presentation. If Silverlight promises as delivered, it will finally be the technology to realize the goals of Java Applets and Flash. Should be fun!
- WPF is hard technology to learn: it is not unusual for developers to flounder for several weeks or even months while in the learning process
- WPF is Vector based, rather than Bitmap based. This should bring the end of developing for specific screen resolutions
- WPF is optimized for integrated media
- Silverlight is a subset of WPF. Small install, runs in a browser not unlike Flash. Cross-platform capable. As such, it cannot do everything WPF can, such as 3D.
- For more robust web apps, WPF can be run inside the browser. This requires WPF to be installed on the machine, and so it will only work on Windows, and currently only in IE (although other browser support on Windows is expected). If you see a web page with an “.xbap” extension, this is WPF running a browser.
- Having the same skill set from Silverlight to full WPF GUIs allows developers to leverage the same skills to do many different UIs
- Silverlight 1.1 (now in testing) will allow code-behind and will distribute a mini-CLR. This means you can write and execute C# code in ANY browser on ANY platform.
- WPF has a greatly enhanced ListBox control: complete control over the graphics and implementation of each individual item. Allows dynamic formatting and sizing.
- WPF and XAML are a move towards declarative programming. Simply declare what you want, instead of defining how to create it, and the system does the rest.
- XAML is very friendly for Code Generation – Billy showed a tool he wrote in a few minutes similar to my own PropertyBuilder (see Free Code)
- A quick note: the new language versions (like VB9) have embedded XML tools and object
- Designing XAML: you can use either Visual Studio or Expression Blend
- VS is designed for developers – gives full access to code but cannot do all the design work, such as gradients
- Blend is designed for Designers: great graphics tools, but no access to code
- Blend can execute code that is already present
- The two can be used simultaneously: both open and use the same .proj files – a change in one will be detected and prompted in the other
- Blend XAML does not have Intellisense, but VS does
- Blend is a separate license, but is part of an MSDN subscription
- CONCLUSION: use Blend to develop the XAML, and VS to edit it manually and write code
- WPF Window class is the root visual element
- Very much like the Form class: same properties and events
- Managed by the Application class as part of Window collection
A good question was asked about the future of Windows Forms. This was Billy’s response:
- Forms are not going anywhere: will be supported for a long time to come
- BUT there will be no significant enhancements: all future development will be for WPF
- WPF is more expensive to develop for right now: more resources, more time, high learning curve
- Eventually, WPF will be as easy or easier than Forms
- WPF does not make Forms obsolete
- New applications should be designed in such a fashion that Forms can be replaced by WPF (good separation of UI and Code) or developed for WPF up front (biting the bullet)
- Element is the catch-all term for everything in WPF, like we treat Control today in Forms
- A Control is anything that interfaces with the User: buttons, checkboxes, etc.
- A Container is an Element that contains other elements
- Like Panel (which is an abstract class in WPF) – used for layout and management: there are four basic Panels – StackPanel, Canvas, Grid, and DockPanel – all used for layout
- Or Decorator (such as Borders and the like)
- Item Controls – lists of other elements
- There is no DataGrid in WPF
- Containers have Child element collections
- Controls are limited to a single Content property
- Content can be ANY .Net object – including Containers
- So any Control can be essentially anything
- Non-WPF objects are displayed as their .ToString() implementation
Getting back from lunch, here is a quick update from the last session.
- Content items can be very complex: one example would be making the content of a tooltip a video box
- Buttons traditionally fire their click event upon release, but WPF introduces the ClickMode Enumerator: release, press, and hover.
- TextBlock is the most lightweight text control, even more so than Label (it is missing a lot of events, properties, and methods)
- Menus and Toolbars are ItemControls, managing a list of other controls
- Measurement Units replace pixels – they are device independent, theoretical units – their actual size is relative to system DPI settings
- The Canvas panel type uses absolute positioning and appears to make the most sense to typical Form developers – don’t fall into the trap! It should be used sparingly sense it does not handle Resizing (one of the main goals of WPF)
- There is no Forms to WPF conversion
- Forms can be used in WPF
- Silverlight 1.0 only supports the Canvas panel type, but later versions are supposed to incorporate other panels
- In WPF all Colors become Brushes – this means that whereever there is Color, you can use Gradients, images, shapes, textures, etc.
- NOTE: the new language versions support “Relaxed Delegates”. This means you do not need to define event args for event signatures if they are not needed.
- Data Binding in WPF is very good
- Blend has some tools for assigning Data Binding
- VS does NOT have any tools for Data Binding, you must code the XAML by hand
- XAML uses “Markup Expressions” for variable items such as Data Binding – there is no Intellisense in Markup Expressions
- Elements may have multiple bindings for different properties
- Bindings are defined as Data Context properties: when data binding occurs, the elementsearches up the tree until it finds the first Data Context.
- This does NOT mean it searches for matching properties! It just uses the first one it finds: failing to find one results in a Silent Failure, so nothing happens and there is no Exception to catch.
6:15pm update (post class):
The wireless quit working for a while, and then I ran out of power, so I missed the last two updates.
More on Data Binding:
- Anything that implements IList can be bound to a ListBox
- Data Binding can come from XML, ADO.NET objects like DataSet and DataTable, or a Resource List defined in XAML
- WPF Element properties can be bound to other Elements Properties: this is a potentially very cool feature. The example Billy showed was binding a TextBlock’s FontSize property to a Slider control’s Value. Move the Slider and the Font Size of the TextBlock changes automatically
Some Miscellaneous points:
- VS2008 Properties window has no ABC sort. I hope this is fixed in the GA version because it is awful to constantly scan the window looking for the correct property
- As XML, XAML is case sensitive, which really bothers VB developers
XBAPS – some more on using Silverlight or WPF via a browser:
- Like any web page, XBAPS run in a security sandbox
- Apps delivered by the server: Software-as-a-Service
- Can store small amounts of information in Isolated Storage. Good for configuration and cacheing.
- Requires the .NET Framework 3.0+ – Silverlight does not.
- XBAP takes over the entire browser window – Silverlight does not.
- ASP.NET can deploy Silverlight components like Flash.
- Silverlight is installed in the browser as a plug-in.
Resources – A crucial part of WPF used to define reusable items:
- XAML can contain declared resources
- Used partially for styling
- Can be ANY .NET object,but is usually a WPF object
- The name of the resource is the key in a Resources Collection
- Can be defined at any level of the XAML: application, window, grid, panel, etc.
- Employed like stylesheets
- When looking for a match, walks up the tree until it finds the first one
Data Templates – a way to define layout and binding templates:
- Helps with the separation of code and UI
- Data should not care about how it is displayed
- The UIElement is in charge of the display
- A data template is used to layout data in a display
- Data Template elements can be data bound to object properties or other information
- Defined as a Resource
- Templates can contain other Elements such as Panels, TextBoxes, Images, etc.
- Template assignments can be changed dynamically: apply different templates based on different states
Animation – not just “cartoonish” or movement, animation means “changing visual properties over time”, such as color, opacity, size, position, etc.:
- Has good and bad uses
- Good animation should be a metaphor for a real world experience (opening a folder, for instance)
- Real world movement is more natural than something just appearing or disappearing
- Fading in and out “feels” more comfortable and natural
- Establish a Path or Storyboard (use Path for movement)
- Bind animation to an appropriate property
- Animation classes are used to execute
- There are different Animation classes for each data type, like DoubleAnimation for doubles
- Namespace: System.Windows.Media.Animation
- MediaPlayer wraps the Windows Media Player
- MediaElement wraps MediaPlayer in XAML
- EventTriggers respond to buttons
- MediaElement can be the Content for any Control – you can effectively put video anywhere
- Media can be used to create a VisualBrush
Transforms – used to alter shapes and sizes of graphics
- A Transform is a system that maps a coordinate space to a different coordinate space
- Unlike GDI+, you can simply declare Transforms in WPF and they “just happen”
- TranslateTransform is used to offset hte starting coordinate
- There areTransforms for Scaling, Skewing, and Rotating
- MatrixTransform is used to apply multiple Transforms
- RenderTransform will apply the transform withoutupdating the Layout
- LayoutTransform will adjust the WPF layout to accomadate the Transform
Styles – like CSS, styles are used to change the look of Elements:
- Declared as a StaticResource
- Allows you to define multiple properties simultaneously
- Styles can be assigned at any level or globally for a type
- Styles can inherit from other styles using the BasedOn attribute
Ink – add Ink capabilities anywhere:
- Bolted on to Windows Forms, but built in to WPF
- Use an InkCanvas and set the background to any element
- You can Ink over anything, including streaming video
- Ink also has Recognition capabilities via the System.Windoes.Ink.InkAnalyzer class.
Whew!? There is more I could add, but what a day!? I think these pre and post conference seminars are the best part of VSLive!? See you tomorrow!