views:

239

answers:

1

If you are creating a WPF window or a WPF page, you can bind commands to functions within the XAML.

<Page x:Class="WpfPageApplication.Page1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:WpfPageApplication="clr-namespace:WpfPageApplication"
Title="Page1" Background="LightGray"
>
<Page.CommandBindings>
    <CommandBinding 
        Command="WpfPageApplication:PizzaCommands.ConfigurePizza" 
        Executed="OnConfigurePizza" />
</Page.CommandBindings>

There is another type of WPF form: a PageFunction. But it doesn't let you type:

<PageFunction.CommandBindings>

I can guess two possible explanations:

  • Because PageFunction is a generic object, you have to somehow enter the generic parameters into the XAML.
  • It's just an inconsistency in the framework.

Does anyone know how I can configure the CommandBindings for a PageFunction within the XAML? (I know I can do it in the code, but that's not the point).

+2  A: 

PageFunction ultimately derives from Page, so I'm fairly certain you can just use <Page.CommandBindings> to define your command bindings. Certainly you can use <Page.Resources> in a PageFunction to define its resources.

Why can't you use <PageFunction.CommandBindings>? I don't know, but I think you're probably right when you say it has to do with the fact that PageFunction is a generic type. You'd need some way in XAML to say what the underlying type is. I think that's possible in the .NET 4.0 version of XAML but not in the current version.

Matt Hamilton
I tried <Page.CommandBindings>. It works.
Andrew Shepherd