使用键绑定命令进行帧导航?

时间:2010-11-14 17:38:02

标签: wpf wpf-controls binding

我想使用键盘上的“Ctrl”和“H”按钮将页面加载到框架中并使用键绑定。我可以加载页面。它现在正在运作。我想知道我是否可以覆盖UriSource链接与它现在的框架。我在XML中分配UriSources,我需要覆盖一个实例,而不是引入新的UriSource来保持索引不被更改。有任何想法吗?提前谢谢!

public partial class MainWindow : Window
{
    public static RoutedUICommand LoadShareSelectedCommand = new RoutedUICommand();
    public MainWindow()
    {
        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));
    }
}

0 个答案:

没有答案