Frame navigation with key binding command?
I’d like to load a page into frame with key binding using ‘Ctrl’ and ‘H’ buttons from a keyboard. I can load page. It is working now. I am wondering if I can just override UriSource link with what it is now into frame. I assign UriSources in XML and I need to override one instance instead of introducing new UriSource to keep the index not changed. Any ideas? Thank you in advance!
public partial class MainWindow : Window
{
public static RoutedUICommand LoadShareSelectedCommand = new RoutedUICommand();
public MainWindow()开发者_如何学Go
{
InitializeComponent();
this.CommandBindings.Add(new CommandBinding(LoadShareSelectedCommand, LoadShareSelectedCommandExecuted));
KeyGesture kg = new KeyGesture(Key.H, ModifierKeys.Control);
InputBinding ib = new InputBinding(LoadShareSelectedCommand, kg);
this.InputBindings.Add(ib);
}
private void LoadShareSelectedCommandExecuted(object sender, ExecutedRoutedEventArgs e)
{
this.ContentFrame.NavigationService.Navigate(new Uri("Pages/SharesSelected.xaml", UriKind.Relative));
}
private void LoadShareSelectedCommand_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = true;
}
private void NavShareSelected(object sender, RoutedEventArgs e)
{
this.ContentFrame.NavigationService.Navigate(new Uri("Pages/SharesSelected.xaml", UriKind.Relative));
}
}
精彩评论