![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | Databinding and Commands Working on May CTP... I'm trying to bind to a static class : public static class MyCommands { public static RoutedCommand ClearAll; static MyCommands () { InputGestureCollection ic = new InputGestureCollection(); ic.Add(new KeyGesture(Key.P,ModifierKeys.Control)); ClearAll = new RoutedUICommand("ClearAll", "clear", typeof(Window1),ic); } public static string Name { get { return "ok"; } } } And trying to use it on a Menuitem <MenuItem Name="mi1" Command="c:MyCommands.ClearAll"" Header="x:Static c:MyCommands.Name}" /> Everything works fine if i remove static operator on classe definition, any idea why? -- Corrado Cavalli [Microsoft .NET MVP-MCP] UGIdotNET - http://www.ugidotnet.org Weblog: http://blogs.ugidotnet.org/corrado |
| | #2 (permalink) |
| Guest | RE: Databinding and Commands There are RoutedCommand and ICommand samples in the SDK: http://windowssdk.msdn.microsoft.com.../ms771540.aspx The negative with the link is that it takes you to a 72 megabyte download to Beta 2 samples. The positive is that you get a lot of samples you can easily search through to find code samples...the RoutedCommand sample built on the latest WPF release. The following syntax may be of interest to you: <CommandBinding Command="{x:Static custom:Window1.ColorCmd}" Executed="WindowColorCmdExecuted" CanExecute="ColorCmdCanExecute"/> If the architecture of routed command doesn't work, you will need to implement an ICommand which is easy to do...and there is an SDK sample too ![]() "Give a man a fish, and you feed him for a day. Teach a man to fish, and you feed him for a lifetime." ...I think I prefer..."Learn to fish, and feed yourself for a lifetime." "Corrado Cavalli [MVP]" wrote: > Working on May CTP... > > I'm trying to bind to a static class : > > public static class MyCommands > { > public static RoutedCommand ClearAll; > static MyCommands () > { > InputGestureCollection ic = new InputGestureCollection(); > ic.Add(new KeyGesture(Key.P,ModifierKeys.Control)); > ClearAll = new RoutedUICommand("ClearAll", "clear", typeof(Window1),ic); > } > > public static string Name > { > get { return "ok"; } > } > } > > And trying to use it on a Menuitem > > <MenuItem Name="mi1" Command="c:MyCommands.ClearAll"" Header="x:Static > c:MyCommands.Name}" /> > > Everything works fine if i remove static operator on classe definition, any > idea why? > > > -- > Corrado Cavalli [Microsoft .NET MVP-MCP] > UGIdotNET - http://www.ugidotnet.org > Weblog: http://blogs.ugidotnet.org/corrado > > > > > > |
| |
| |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| DataBinding and ListView | Lammert | Avalon | 0 | 02-14-2008 02:04 PM |
| Databinding issue | IHaveThePower | Avalon | 0 | 11-02-2007 07:02 AM |
| Databinding problem | black_nm | Avalon | 0 | 07-03-2007 05:35 AM |
| DataBinding to indexer | =?Utf-8?B?QWxleEI=?= | Avalon | 11 | 09-25-2006 08:31 AM |
| 3D, Canvas, and Databinding | Christopher Bennage | Avalon | 5 | 05-31-2006 02:34 PM |