We would like to be able to set the focus to one of the buttons (e.g., OK/Accept) when one of the xamGrid popups appear.
Specifically, when the FilterSelectionControl or the CompoundFilterDialogControl become visible, we want the focus to start on the OK button.
We have played around with the templates from the generic.xaml for the XamGrid to get this to work, without any success so far.
Are there any suggestions on how to accomplish this?
Hello Gerard,
To get the OK button to focus on when opening of the FilterSelectionControl or the CompoundFilterDialogControl, I would recommend pasting the Styles for those two from the generic.xaml file into your project. This way, you can handle the Loaded event of these buttons.
In the Loaded event, cast the sender to a button and call Button1.Focus(); Also, there is a Binding on the IsEnabled property of the FilterSelectionControl. You will need to remove the setting of the IsEnabled property to have this method work as well.
I have attached a sample application to demonstrate the above.
Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewDeveloper Support Engineer IInfragistics Inc.www.infragistics.com/support
Hello Gerard,Just checking in, did you have any other questions or concerns on this matter?
Sincerely, AndrewDeveloper Support Engineer IInfragistics Inc.www.infragistics.com/support
Your example worked and I managed to implement it in my code. Rather then including the XAML in every grid, in all our projects, I would like to include the xaml in a generally used xaml and start using commanding.
I got the commanding to work on the loaded event but how can I pass the button as CommandTaget.
I tried this but it doesnot work.
<Button x:Name="AcceptButton" Margin="0,0,5,0" Width="73" Content="{TemplateBinding OKButtonText}" ig:Commanding.CommandTarget="{Binding ElementName=AcceptButton}"><igBase:Commanding.Commands> <igBase:CommandSourceCollection> <ig:FilterSelectionControlCommandSource CommandType="AcceptChanges" ElementName="Click"> </ig:FilterSelectionControlCommandSource> <igPrim:XamGridPopupCommandSource CommandType="ClosePopup" EventName="Click"> </igPrim:XamGridPopupCommandSource> </igBase:CommandSourceCollection></igBase:Commanding.Commands><igBase:Commanding.Command> <service:SetFocusCommandSource EventName="Loaded" /></igBase:Commanding.Command></Button>
In the event, the parameter is always null. I could get the button via:
public object GetParameter(CommandSource source){ var b = source.SourceElement as Button; if (b != null) return b; else return source;}
but this is not the way it should work. Also this only works the first time the control is displayed. The second time the focus is not set.
To get the FilterMenu button and the Excel Custom filter button to focus using commands, I would recommend setting the ig:Commanding.CommandTarget on the button to {Binding RelativeSource={RelativeSource Self}}.
Then, in the Execute method of your custom focus command, cast the object parameter to a FocusCommandSource and get the button through: Button b = FocusCommandSource1.SourceElement as Button. Then call b.Focus();
I have attached a sample application that demonstrates the above.
By adding
ig:Commanding.CommandTarget="{Binding RelativeSource={RelativeSource Self}}"
to my button control, all my problems were solved.
Thanks.