Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1690
XamGrid and Commanding Framework
posted

Hello,

I would like to create two commands that will take as parameter a XamGrid and

1) Show the columnchooser for that grid

2) Export data to excel..

Those commands should be invoked by a context menu item or a simple button or a ribbon tool or whatever element is supported by the commanding framework.

I have tried to do so, but with no success...

Is it that difficult?

What am i missing?

Regards,

Michael

Parents
  • 40030
    Offline posted

    Hi Michael. 

    Here is a quick walkthrough on how to do this for the column chooser, excel exporting would be basically the same. 

    1. Implement ICommandTarget on your UserControl:

    public partial class MainPage : UserControl, ICommandTarget

    2.  in the SupportsCommand method, return true for any command that you want to support:

     bool ICommandTarget.SupportsCommand(ICommand command)

            {

                return command is OpenColumnChooserCommand;

            }

    3. in the GetParameter method, return what object you want to perform an action on, in this case the xamGrid:

    object ICommandTarget.GetParameter(Infragistics.Controls.CommandSource source)

            {

                return grid;

            }

     

    4. Create a CommandSource class, this will be used to hook the event up to your button:

     public class MyGridCommands : CommandSource

        {

            protected override ICommand ResolveCommand()

            {

                return new OpenColumnChooserCommand();

            }

        }

    5. Implement the command

    public class OpenColumnChooserCommand : CommandBase

        {

            public override bool CanExecute(object parameter)

            {

                if (parameter is XamGrid)

                    return true;

     

                return false;

            }

     

            public override void Execute(object parameter)

            {

                XamGrid grid = parameter as XamGrid;

                if (grid != null)

                    grid.ShowColumnChooser();

            }

        }

    6. Finally, hook up your command to your button:

    <Button Content="Column Chooser">

                        <ig:Commanding.Command>

                            <local:MyGridCommands EventName="Click" >

                            </local:MyGridCommands>

                        </ig:Commanding.Command>

                    </Button>

    Hope this helps simplify things.

    -SteveZ

Reply Children