setFocus to textbox on NavigationViewItem clicked #4805
-
Hi, I'm trying to get a I have tried with a selection changed event on the shellpage, OnNavigatedTo on the page (in the frame), where the frame navigation is handled, ... Can this be done? When I click in the frame content (not the textbox) it does focus (when textbox.Focus(FocusState.Programmatic) is in OnNavigatedTo) Thanks in advance Simplified imageShellPage<NavigationView
x:Name="NavigationViewControl"
Canvas.ZIndex="0"
IsBackButtonVisible="Collapsed"
IsBackEnabled="{x:Bind ViewModel.IsBackEnabled, Mode=OneWay}"
SelectedItem="{x:Bind ViewModel.Selected, Mode=OneWay}"
IsSettingsVisible="True"
ExpandedModeThresholdWidth="1280"
DisplayModeChanged="NavigationViewControl_DisplayModeChanged"
Header="{x:Bind ((ContentControl)ViewModel.Selected).Content, Mode=OneWay}"
SelectionChanged="NavigationViewControl_SelectionChanged">
<NavigationView.MenuItems>
<!--
TODO: Update item titles by updating <x:Uid>.Content entries in Strings/en-us/Resources.resw.
https://docs.microsoft.com/windows/uwp/app-resources/localize-strings-ui-manifest#refer-to-a-string-resource-identifier-from-xaml
TODO: Update item icons by updating FontIcon.Glyph properties.
https://docs.microsoft.com/windows/apps/design/style/segoe-fluent-icons-font#icon-list
-->
<NavigationViewItem x:Uid="Shell_Main" helpers:NavigationHelper.NavigateTo="AppName.ViewModels.MainViewModel">
<NavigationViewItem.Icon>
<FontIcon FontFamily="{StaticResource SymbolThemeFontFamily}" Glyph=""/>
</NavigationViewItem.Icon>
</NavigationViewItem>
<NavigationViewItem x:Uid="Shell_Insert" helpers:NavigationHelper.NavigateTo="AppName.ViewModels.InsertViewModel">
<NavigationViewItem.Icon>
<FontIcon FontFamily="{StaticResource SymbolThemeFontFamily}" Glyph=""/>
</NavigationViewItem.Icon>
</NavigationViewItem>
<NavigationViewItem x:Uid="Shell_Extract" helpers:NavigationHelper.NavigateTo="AppName.ViewModels.ExtractViewModel">
<NavigationViewItem.Icon>
<FontIcon FontFamily="{StaticResource SymbolThemeFontFamily}" Glyph=""/>
</NavigationViewItem.Icon>
</NavigationViewItem>
<NavigationViewItem x:Uid="Shell_List" helpers:NavigationHelper.NavigateTo="AppName.ViewModels.ListViewModel">
<NavigationViewItem.Icon>
<FontIcon FontFamily="{StaticResource SymbolThemeFontFamily}" Glyph=""/>
</NavigationViewItem.Icon>
</NavigationViewItem>
</NavigationView.MenuItems>
<NavigationView.HeaderTemplate>
<DataTemplate>
<Grid>
<TextBlock
Text="{Binding}"
Style="{ThemeResource TitleTextBlockStyle}" />
</Grid>
</DataTemplate>
</NavigationView.HeaderTemplate>
<i:Interaction.Behaviors>
<behaviors:NavigationViewHeaderBehavior
DefaultHeader="{x:Bind ((ContentControl)ViewModel.Selected).Content, Mode=OneWay}">
<behaviors:NavigationViewHeaderBehavior.DefaultHeaderTemplate>
<DataTemplate>
<Grid>
<TextBlock
Text="{Binding}"
Style="{ThemeResource TitleTextBlockStyle}" />
</Grid>
</DataTemplate>
</behaviors:NavigationViewHeaderBehavior.DefaultHeaderTemplate>
</behaviors:NavigationViewHeaderBehavior>
</i:Interaction.Behaviors>
<!--<ScrollViewer>-->
<Grid Margin="{StaticResource NavigationViewPageContentMargin}">
<Frame x:Name="NavigationFrame" />
</Grid>
<!--</ScrollViewer>-->
</NavigationView> |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi @massamino , the NavigationView is not part of the CommunityToolkit, so you might want to try out the WinUI repo for any questions related to this control. That said, have you tried setting the textbox.Focus(FocusState.Programmatic) in the Loaded event of the Page instead of the OnNavigatedTo? That might work. |
Beta Was this translation helpful? Give feedback.
Hi @massamino , the NavigationView is not part of the CommunityToolkit, so you might want to try out the WinUI repo for any questions related to this control.
That said, have you tried setting the textbox.Focus(FocusState.Programmatic) in the Loaded event of the Page instead of the OnNavigatedTo? That might work.