Windows Vista Forums

Databinding and Commands

  1. #1


    Corrado Cavalli [MVP] 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






      My System SpecsSystem Spec

  2. #2


    =?Utf-8?B?VGhlUkhvZ3Vl?= 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
    >
    >
    >
    >
    >
    >


      My System SpecsSystem Spec

Databinding and Commands

Similar Threads
Thread Forum
ASP.NET two way databinding with nulls
I've seen this question asked 100 times, but with no reasonable answer, other than to extend a control etc. Sorry if I'm going over old ground. ...
.NET General
Databinding issue
Hi I am using a XmlDataProvider to bind my Controls. I recieve XML Data from a port.I want to refresh the view everytime i get new data.How can i...
Avalon
Databinding problem
Hi, I have an class Test (INotifyPropertyChanged) which contains a property (Value) of int? type. The Value property is bounded to a TextBox. If...
Avalon
DataBinding to indexer
Hi all, I'm searching for a solution to bind a UIElement to a custom Data object with dynamic number of properties. The first idea was to wrap...
Avalon
DataBinding to indexer
Hi all, I'm searching for a solution to bind a UIElement to a custom Data object with dynamic number of properties. The first idea was to wrap...
Avalon
Animating databinding changes ?
I was toying with WPF and doing some gratuitous effects, when I wondered if the following idea was possible. I display a card (e.g. think about...
Avalon
3D, Canvas, and Databinding
I'm looking to replicate something I once did in Flash, but I'm not sure what is the best approach. Essentialy, I have a collection of objects that...
Avalon