I need a context menu for a cell or even at the sheet level that allows me to define the commands that are used, not use the predefined commands in the SpreadsheetContextMenuProvider. Is this possible?
There's nothing stopping you from using your own ICommand. Maybe it would help to start from the beginning. If you want to provide a custom context menu for a part of the xamSpreadsheet you do that using the ContextMenuProvider property as described in this help topic. Basically you are defining a ResourceDictionary of XamContextMenu instances where the x:Key is the string value of the SpreadsheetContextMenuArea enumeration. In the help topic its redefining the context menu for the cells. You define the XamMenuItem's that are to be displayed in the xamContextMenu. The XamMenuItem has a Command property of type ICommand. (Note I'm not talking about the attached Command property that you seem to be setting above - that's for use with a commandsource.) The DataContext of that ContextMenu will be a SpreadsheetMenuDataContext instance that the spreadsheet will assign at runtime when it is about to show the menu. So if you need to access something in the xamSpreadsheet (like use its DataContext) then you can do that through that object. For example the SpreadsheetMenuDataContext has a property named Spreadsheet that returns the associated xamSpreadsheet so if you needed to get to the datacontext of that you could do something like <XamMenuItem Tag="{Binding Path=Spreadsheet.DataContext}" /> If you still have difficulty please post a sample with as far as you got and what problem you hit and we can help you get it working.
I am still not seeing what I need. All the examples and links still use the igLocalPrim:SpreadsheetCommandSource. I need my own ICommand.
Something like this that you could do as a context menu for a WPF DataGrid:
<DataGrid.ContextMenu> <ContextMenu > <MenuItem Header="Totals Only" Command="{Binding Path=ShowTotalsOnly}"/> </ContextMenu></DataGrid.ContextMenu>
I tried creating my Own CommandSource Class, Implementing the ICommandTarget interface on my WPF user control but teh Click is not fireing Execute. When I click on the menu item, the comaand source is called and the IComamnd is created but not executed. here is some of my code.
XAML:
<ig:XamMenuItem Header="Test"> <ig:Commanding.Command> <cmd:ShowTotalsOnlySource EventName="Click" TargetName="UcMain"/> </ig:Commanding.Command> </ig:XamMenuItem>
Source and Command
public class ShowTotalsOnlySource : Infragistics.Controls.CommandSource {protected override ICommand ResolveCommand(){ ICommand cmd = null; try { cmd = new ShowTotalsOnlyCommand(); } catch(Exception ex) { Debug.Print(ex.Message); }
return cmd; } }
public class ShowTotalsOnlyCommand : Infragistics.CommandBase { public ShowTotalsOnlyCommand() { Debug.Print("Construct Command"); } public override bool CanExecute(object parameter) { return true; }
public override void Execute(object parameter) { //Add Save code here Debug.Print("Command Clicked"); } }
The interface methods in my user control (ucMain), never fire. I think my target may be wrong.
public bool SupportsCommand(ICommand command) { return true; }
public object GetParameter(CommandSource source) { return source; }
Thanks for your help.
To clarify, you do not need to use our commands. The XamMenuItem has a Command property which you can supply your own command to. Also, the DataContext of the xamContextMenu will be a SpreadsheetMenuDataContext which gives you access to information about the menu, including a reference to the spreadsheet.
http://es.infragistics.com/help/wpf/infragisticswpf4.controls.grids.xamspreadsheet.v16.2~infragistics.controls.grids.primitives.spreadsheetmenudatacontext_properties
e.g.In our default context menu, a couple of the Tab related menu items bind to the Spreadsheet property of that DataContext:
<ig:XamMenuItem Header="{Binding Source={StaticResource menuItemInsertWorksheetsHeader}, Path=Value}"> <ig:XamMenuItem.Visibility> <Binding Path="Spreadsheet.AllowAddWorksheet" Converter="{StaticResource boolToVisConverter}"> <Binding.FallbackValue> <sys:Boolean>true</sys:Boolean> </Binding.FallbackValue> </Binding> </ig:XamMenuItem.Visibility> <ig:Commanding.Command> <igLocalPrim:SpreadsheetCommandSource CommandType="InsertNewWorksheets" EventName="Click" /> </ig:Commanding.Command> </ig:XamMenuItem>
We also have a topic on working with commands and the spreadsheet here:http://es.infragistics.com/help/wpf/spreadsheet-work-commands
Let me know if you have any questions regarding this matter.
I saw that example but I want to do other things that are not included in predefined commands in the SpreadsheetContextMenuProvider. I want to execute my own custom ICommand that has nothing to do with fonts or moving cells. I just need to execute some code on my data context that is hosting the XamSpreadsheet. I assume the sample limits me to the predefined commands due to the context being either cell or sheet or whatever. But can't I define a command using relative source to get to my data context?
Hello Terence, Thank you for contacting Infragistics. You can define your own custom context menu by creating a new instance of SpreadsheetContextMenuProvider, and set it to the ContextMenuProvider propoerty of the XamSpreadsheet.
Please refer to the following help topic for a complete tutorial:http://es.infragistics.com/help/wpf/spreadsheet-work-context-menu