![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 Specs![]() |
| | #3 (permalink) |
| | 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 Specs![]() |
| | #4 (permalink) |
| | 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 Specs![]() |
| | #5 (permalink) |
| | 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 Specs![]() |