我正在开发一个WinUI 3应用程序,有一件事我无法找到或理解,那就是如何在启动应用程序时打开(NavigationViewItem,基本上是Home选项卡,homePage
)。我有App.xaml和MainWindow.xaml。我在Stackoverflow上发现了另一个问题,主要是here,但它确实使用了ViewModel,但我没有使用ViewModel。我如何实现这种行为?
这是MainWindow.xaml
<Window
x:Class="Ankara_Online.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Ankara_Online"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<StackPanel>
<NavigationView x:Name="_navigationView"
IsSettingsVisible="False"
IsBackButtonVisible="Collapsed"
IsBackEnabled="False"
Header="Home Page"
AlwaysShowHeader="False"
PaneTitle="navigationPane"
PaneDisplayMode="Top"
ExpandedModeThresholdWidth="500"
SelectionFollowsFocus="Disabled"
IsTabStop="False">
<NavigationView.Resources>
<SolidColorBrush x:Key="NavigationViewTopPaneBackground" Color="#195caa" />
</NavigationView.Resources>
<NavigationView.MenuItems>
<NavigationViewItem Content="Home" Tag="homePage" x:Name="homePageItem">
<NavigationViewItem.Icon>
<SymbolIcon Symbol="Play" />
</NavigationViewItem.Icon>
</NavigationViewItem>
<NavigationViewItem Content="Applications and Sector Files" Tag="softwareSectorFilePage" x:Name="softwareSectorFilePageItem">
<NavigationViewItem.Icon>
<SymbolIcon Symbol="Save" />
</NavigationViewItem.Icon>
</NavigationViewItem>
<NavigationViewItem Content="Documentation" Tag="DocumentationPage" x:Name="DocumentationPageItem">
<NavigationViewItem.Icon>
<SymbolIcon Symbol="Refresh" />
</NavigationViewItem.Icon>
</NavigationViewItem>
<NavigationViewItem Content="Settings" Tag="SettingsPage" x:Name="SettingsPageItem">
<NavigationViewItem.Icon>
<SymbolIcon Symbol="Refresh" />
</NavigationViewItem.Icon>
</NavigationViewItem>
</NavigationView.MenuItems>
<NavigationView.PaneCustomContent>
<HyperlinkButton x:Name="PaneHyperlink" Content="More info" Margin="12,0" Visibility="Collapsed" />
</NavigationView.PaneCustomContent>
<NavigationView.PaneFooter>
<StackPanel x:Name="FooterStackPanel" Orientation="Vertical" Visibility="Visible">
<NavigationViewItem Icon="Download" AutomationProperties.Name="download" />
</StackPanel>
</NavigationView.PaneFooter>
<Frame x:Name="contentFrame" />
</NavigationView>
</StackPanel>
</Window>
1条答案
按热度按时间ig9co6j11#
假设你有一个
HomePage.xaml
,你可以这样做:主窗口.xaml
主窗口.xaml.cs