Welcome to Windows Presentation Foundation (WPF)
Top Tasks :

WPF Community Bloggers

Friday, July 25, 2008 - Posts

  • Fixing WPF Command Routing

    Bill Kempf , a fellow WPF Disciple , was lamenting the fact that by default a CommandBinding can only refer to a handler defined in the code behind of the Window/Page/UserControl in which it's defined. He wished that a syntax similar to the following was possible < Window > < Window.CommandBindings > < CommandBinding Command ="foo:MyCommands.FooCommand" Executed ="{Event Target={StaticResource MyPresenter}, Handler=OnFooCommand}" /> </ Window.CommandBindings > </ Window > I took that scenario as my starting point. The first issue I saw was that I needed a markup extension that let's you specify a Target Object and the name of a handler on that Target returning a ExecutedRoutedEventHandler. So I made one. The Markup Extension exposes two properties: Target (of type object) and Handler of Type String. The ProvideValue override (shown below) uses reflection to get a handle on the function and creates a lambda that invokes it for the result. Read More...
  • A Brief Proof That Unrelentingly Catchy Tunes Do Not Good Music Make

    ABBA. QED. Read More...
  • Great new way for using RoutedCommands with the ViewModel pattern in WPF

    Josh Smith just published a great article about his solution to using RoutedCommands in WPF. The problem he solves, has been solved by others before, however, I think this is a very lightweight succinct way of doing it. Basically, when you set a command to a button, you will have to handle that logic (canExecute and Execute) in the codebehind of the view. Since you are (hopefully) using a MVC, MVP or MVVM approach, you would rather not go through the codebehind of the view, but directly route the commands to the appropriate viewmodel/controller. He creates a relaying object that does just that. This results in a completely empty codebehind for the view, which is exactly what I like! Good job Josh! Read More...

Copyright © 2006 Microsoft Corporation. All Rights Reserved. | Terms of Use | Privacy Statement | Contact Us