NavigationViewContentPresenter consumes F5 key and prevents page-level handling #1641
Unanswered
Koichi-Kobayashi
asked this question in
Q&A
Replies: 2 comments
-
|
NavigationViewContentPresenter.cs protected override void OnPreviewKeyDown(KeyEventArgs e)
{
if (e.Key == Key.F5)
{
e.Handled = true;
return;
}
base.OnPreviewKeyDown(e);
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
I think this should be okay... public partial class XxxPage : UserControl, INavigableView<XxxPageViewModel>
public ExplorerPage(XxxPageViewModel viewModel)
{
InitializeComponent();
AddHandler(Keyboard.PreviewKeyDownEvent,
new KeyEventHandler(OnPreviewKeyDownHandledToo),
handledEventsToo: true);
}
private void OnPreviewKeyDownHandledToo(object sender, KeyEventArgs e)
{
// TODO: Here is the custom F5 processing
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I investigated this behavior using a custom route-tracing utility that logs the PreviewKeyDown event along the visual tree from the focused control up to the window.
As a result, I found that NavigationViewContentPresenter (PART_NavigationViewContentPresenter) in WPF-UI handles the F5 key internally and sets Handled = true during the PreviewKeyDown phase.
Because of this, the F5 key event is consumed before it reaches my page (ExplorerPage) or the contained DataGrid, even though the focused element is the DataGrid.
This means that, unlike other keys such as F2, it is not possible to implement custom F5 handling at the page level, since the event is already marked as handled by the NavigationView internals.
At the moment, the only workaround is to intercept F5 at a higher level (e.g. Window-level KeyBinding) before NavigationView processes it, but this makes it difficult to implement page-specific refresh behavior.
Is there an intended way to disable or override the internal F5 handling in NavigationView, or to allow the key event to propagate to child content?
Usage
[Preview] Key=F5 Handled=False Focus=DataGrid Sender=MainWindow Name= Src=DataGrid SrcName=SplitFileDataGrid
[Route] Key=F5 Handled=False At=MainWindow Name=
[Route] Key=F5 Handled=False At=AdornerDecorator Name=
[Route] Key=F5 Handled=False At=ClientAreaBorder Name=
[Route] Key=F5 Handled=False At=ContentPresenter Name=ContentPresenter
[Route] Key=F5 Handled=False At=Grid Name=
[Route] Key=F5 Handled=False At=NavigationView Name=RootNavigation
[Route] Key=F5 Handled=False At=Grid Name=
[Route] Key=F5 Handled=False At=Border Name=
[Route] Key=F5 Handled=False At=Grid Name=
[Route] Key=F5 Handled=True At=NavigationViewContentPresenter Name=PART_NavigationViewContentPresenter <---this
[Route] Key=F5 Handled=True At=ContentPresenter Name=PART_FrameCP
[Preview] Key=F5 Handled=True Focus=DataGrid Sender=ExplorerPage Name= Src=DataGrid SrcName=SplitFileDataGrid
[Route] Key=F5 Handled=True At=ExplorerPage Name=
[Route] Key=F5 Handled=True At=Border Name=
[Route] Key=F5 Handled=True At=ContentPresenter Name=
[Route] Key=F5 Handled=True At=Grid Name=
[Route] Key=F5 Handled=True At=Grid Name=
Beta Was this translation helpful? Give feedback.
All reactions