Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - Binding to custom command in InputBindings

 
 
Old 04-22-2006   #1 (permalink)
Johann MacDonagh


 
 

Binding to custom command in InputBindings

I'm having trouble creating a MouseBinding for my ListView. Here's the line:

<MouseBinding Command="{Binding Path=DataContext.ViewTransactions,
RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type
Grid}}}" Gesture="LeftDoubleClick" />

I've used that same binding elsewhere on my page and it works fine. However,
when I use it on the MouseBinding, I get this error:

Error at element 'RuntimePropertyInfo' in markup file 'MyPage.xaml' : Object
of type 'System.Windows.Data.Binding' cannot be converted to type
'System.Windows.Input.ICommand'..

Any suggestions? Using a converter doesnt seem to work. It seems like the
Command property in MouseBinding doesnt want to allow actual {Binding }
statements and instead wants only a simple string with built in commands
(ApplicationCommands.Cut, etc...)

Thanks

My System SpecsSystem Spec
Old 04-24-2006   #2 (permalink)
Marcus


 
 

Re: Binding to custom command in InputBindings

One thing for sure, I think the Command member simply doesn't like the
"{Binding }" statement...

I've been using custom commands in KeyboardGestures a lot.... It might
simply be that {Binding} doesn't return the appropriate thing when
refering to a public static readonly member?

At the same time, a command is not something which is likelly to change
over time... Using a binding might not be the most efficient
solution...

Might I suggest using a syntax like:

Command="local:CustomClass.CustomCommand" instead...

in which:

local --> XML Namespace defined for the project where your custom class
is located.
CustomClass --> The custom class on which the custom command is
defined.
CustomCommand --> the RoutedCommand, declared as public static readonly
on the CustomClass class.

My System SpecsSystem Spec
Old 04-24-2006   #3 (permalink)
Johann MacDonagh


 
 

Re: Binding to custom command in InputBindings

Thanks for your reply. I tried building a simple class with a public static
custom command and tried referencing it like you suggested. The runtime error
I get is:

Error at element 'MouseBinding' in markup file 'MyPage.xaml' :
'local:Glob.Test' string is not a valid value for 'Command' property of type
'ICommand'..

The {Binding} syntax is used on other areas that support command (e.g.
buttons, menu items, etc...). Although the command is unlikely to change, I
can use the OneTime Mode option to specify a startup binding. No extra
resources are used to update this binding.

I'm going to submit this as a bug, since it appears to only work for built
in commands (ApplicationCommands.Copy). Thanks for your help!

"Marcus" wrote:

> One thing for sure, I think the Command member simply doesn't like the
> "{Binding }" statement...
>
> I've been using custom commands in KeyboardGestures a lot.... It might
> simply be that {Binding} doesn't return the appropriate thing when
> refering to a public static readonly member?
>
> At the same time, a command is not something which is likelly to change
> over time... Using a binding might not be the most efficient
> solution...
>
> Might I suggest using a syntax like:
>
> Command="local:CustomClass.CustomCommand" instead...
>
> in which:
>
> local --> XML Namespace defined for the project where your custom class
> is located.
> CustomClass --> The custom class on which the custom command is
> defined.
> CustomCommand --> the RoutedCommand, declared as public static readonly
> on the CustomClass class.
>
>

My System SpecsSystem Spec
Old 04-25-2006   #4 (permalink)
Marcus


 
 

Re: Binding to custom command in InputBindings

That seems to be indeed bug report material...

If you get an answer from Microsoft on the matter, would you post it
back here?!?

I would be interested in knowing the details of the problem...

Thanks

My System SpecsSystem Spec
Old 04-25-2006   #5 (permalink)
Johann MacDonagh


 
 

Re: Binding to custom command in InputBindings

Actually, it appears that the Command property of the KeyBinding /
MouseBinding class is not registered as a dependency property. Since it
isn't, I can't bind to it.

I'm sure they've already fixed it in an upcoming release, but I submitted a
bug report anyway.

Thanks for your help! When I get a reponse back from Microsoft I'll post it
back here.

"Marcus" wrote:

> That seems to be indeed bug report material...
>
> If you get an answer from Microsoft on the matter, would you post it
> back here?!?
>
> I would be interested in knowing the details of the problem...
>
> Thanks
>
>

My System SpecsSystem Spec
 

Thread Tools



Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46