Welcome to Windows Presentation Foundation (WPF)
Top Tasks :

WPF Community Bloggers

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...
Published Friday, July 25, 2008 11:58 PM by Brownie Points
Filed under:

Comments

No Comments
Anonymous comments are disabled

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