<?xml version="1.0" encoding="utf-8"?>
<Window
x:Class="ThaiTong.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:ThaiTong"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="ThaiTong">
<Window.SystemBackdrop>
<MicaBackdrop />
</Window.SystemBackdrop>
<NavigationView IsBackEnabled="True" BackRequested="NavigationView_BackRequested" SelectionChanged="NavigationView_SelectionChanged" IsSettingsVisible="True" Header="header" PaneTitle="AppError" PaneDisplayMode="Left" >
<NavigationView.AutoSuggestBox>
<AutoSuggestBox x:Name="ASB" PlaceholderText="Search" QueryIcon="Find" QuerySubmitted="QuerySubmitted" SuggestionChosen="SuggestionChosen"/>
</NavigationView.AutoSuggestBox>
<NavigationView.MenuItems>
<NavigationViewItem Icon="Play" Content="1" Tag="SamplePage1"/>
<NavigationViewItem Icon="Save" Content="2" Tag="SamplePage2">
<NavigationViewItem.MenuItems>
<NavigationViewItem Icon="Print" Content="6" Tag="SamplePage3"/>
</NavigationViewItem.MenuItems>
</NavigationViewItem>
<NavigationViewItem Icon="Refresh" Content="3" Tag="SamplePage3"/>
<NavigationViewItem Icon="Download" Content="4" Tag="SamplePage4"/>
</NavigationView.MenuItems>
<NavigationView.FooterMenuItems>
<NavigationViewItem Icon="Message" Content="Message" Tag="SamplePage5"/>
</NavigationView.FooterMenuItems>
<Frame x:Name="contentFrame"/>
</NavigationView>
</Window>
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.ApplicationSettings;
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.
namespace ThaiTong
{
/// <summary>
/// An empty window that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainWindow : Window
{
public MainWindow()
{
this.InitializeComponent();
ExtendsContentIntoTitleBar = true;
SetTitleBar(null);
}
private void NavigationView_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args)
{
var selectedItem = (NavigationViewItem)args.SelectedItem;
if (args.IsSettingsSelected)
{
contentFrame.Navigate(typeof(SettingsPage));
}
if ((string)selectedItem.Tag == "SamplePage1") contentFrame.Navigate(typeof(SamplePage1));
else if ((string)selectedItem.Tag == "SamplePage2") contentFrame.Navigate(typeof(SamplePage2));
else if ((string)selectedItem.Tag == "SamplePage3") contentFrame.Navigate(typeof(SamplePage3));
else if ((string)selectedItem.Tag == "SamplePage4") contentFrame.Navigate(typeof(SamplePage4));
else if ((string)selectedItem.Tag == "SamplePage5") contentFrame.Navigate(typeof(SamplePage5));
}
private void NavigationView_BackRequested(NavigationView sender, NavigationViewBackRequestedEventArgs args)
{
if (contentFrame.CanGoBack)
{
contentFrame.GoBack();
}
}
private void SuggestionChosen(AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs args)
{
sender.Text = args.SelectedItem.ToString();
}
private void QuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args)
{
string txt = args.QueryText; //输入的文本
if (args.ChosenSuggestion != null)
{
//从提示框中选择某一项时触发
}
else
{
//用户在输入时敲回车或者点击右边按钮确认输入时触发
}
}
}
}
![image]()