-
-
Notifications
You must be signed in to change notification settings - Fork 24
improve:UI #564
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
improve:UI #564
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| <ui:Page x:Class="Ink_Canvas.Windows.SettingsViews.Pages.SearchPage" | ||
| xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
| xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
| xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
| xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
| xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern" | ||
| xmlns:props="clr-namespace:Ink_Canvas.Properties" | ||
| mc:Ignorable="d" | ||
| Title="Search"> | ||
|
|
||
| <Grid Margin="59,0,59,0"> | ||
| <Grid.RowDefinitions> | ||
| <RowDefinition Height="Auto"/> | ||
| <RowDefinition Height="*"/> | ||
| </Grid.RowDefinitions> | ||
|
|
||
| <!-- 搜索框居中偏上 --> | ||
| <ui:AutoSuggestBox | ||
| x:Name="SearchBox" | ||
| Grid.Row="0" | ||
| MaxWidth="600" | ||
| HorizontalAlignment="Stretch" | ||
| VerticalAlignment="Top" | ||
| Margin="0,80,0,0" | ||
| FontSize="14" | ||
| CornerRadius="8" | ||
| PlaceholderText="{x:Static props:NavStrings.Nav_SearchSettings}" | ||
| QuerySubmitted="SearchBox_QuerySubmitted" | ||
| TextChanged="SearchBox_TextChanged" | ||
| GotFocus="SearchBox_GotFocus" | ||
| KeyDown="SearchBox_KeyDown"> | ||
| <ui:AutoSuggestBox.QueryIcon> | ||
| <ui:FontIcon Icon="{x:Static ui:SegoeFluentIcons.Search}" FontSize="14"/> | ||
| </ui:AutoSuggestBox.QueryIcon> | ||
| </ui:AutoSuggestBox> | ||
|
|
||
| <!-- 搜索提示 --> | ||
| <TextBlock | ||
| x:Name="HintText" | ||
| Grid.Row="1" | ||
| Text="{x:Static props:NavStrings.Nav_SearchSettings}" | ||
| FontSize="13" | ||
| Foreground="{DynamicResource TextFillColorSecondaryBrush}" | ||
| HorizontalAlignment="Center" | ||
| VerticalAlignment="Top" | ||
| Margin="0,24,0,0"/> | ||
| </Grid> | ||
| </ui:Page> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Windows; | ||
| using System.Windows.Input; | ||
| using iNKORE.UI.WPF.Modern.Controls; | ||
|
|
||
| namespace Ink_Canvas.Windows.SettingsViews.Pages | ||
| { | ||
| public partial class SearchPage | ||
| { | ||
| /// <summary> | ||
| /// 选中搜索结果时触发,参数为 PageTag;"__back__" 表示返回 | ||
| /// </summary> | ||
| public static event EventHandler<string> ResultSelected; | ||
|
|
||
| // 由 SettingsWindow 设置的静态搜索数据 | ||
| internal static List<(string Text, string PageTag)> SearchData { get; set; } | ||
|
|
||
| public SearchPage() | ||
| { | ||
| InitializeComponent(); | ||
| Loaded += (s, e) => | ||
| { | ||
| Dispatcher.BeginInvoke(new Action(() => SearchBox.Focus()), | ||
| System.Windows.Threading.DispatcherPriority.Input); | ||
| }; | ||
| } | ||
|
|
||
| private void SearchBox_QuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args) | ||
| { | ||
| if (SearchData == null) return; | ||
|
|
||
| string raw = (args.ChosenSuggestion as string) ?? args.QueryText; | ||
| if (string.IsNullOrWhiteSpace(raw)) return; | ||
|
|
||
| string query = raw.Trim(); | ||
| var match = SearchData.Where(e => e.Text.Equals(query, StringComparison.OrdinalIgnoreCase)) | ||
| .Concat(SearchData.Where(e => e.Text.IndexOf(query, StringComparison.OrdinalIgnoreCase) >= 0)) | ||
| .FirstOrDefault(); | ||
|
|
||
| if (match.Text != null) | ||
| { | ||
| ResultSelected?.Invoke(this, match.PageTag); | ||
| } | ||
| } | ||
|
|
||
| private void SearchBox_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args) | ||
| { | ||
| if (args.Reason != AutoSuggestionBoxTextChangeReason.UserInput) return; | ||
| if (SearchData == null) return; | ||
|
|
||
| string query = sender.Text?.Trim() ?? string.Empty; | ||
| if (string.IsNullOrEmpty(query)) | ||
| { | ||
| sender.ItemsSource = null; | ||
| HintText.Visibility = Visibility.Visible; | ||
| return; | ||
| } | ||
|
|
||
| HintText.Visibility = Visibility.Collapsed; | ||
|
|
||
| var suggestions = SearchData | ||
| .Where(e => e.Text.IndexOf(query, StringComparison.OrdinalIgnoreCase) >= 0) | ||
| .Select(e => e.Text) | ||
| .Distinct() | ||
| .Take(50) | ||
| .ToList(); | ||
|
|
||
| sender.ItemsSource = suggestions; | ||
| sender.IsSuggestionListOpen = suggestions.Count > 0; | ||
| } | ||
|
|
||
| private void SearchBox_GotFocus(object sender, RoutedEventArgs e) | ||
| { | ||
| if (!string.IsNullOrEmpty(SearchBox.Text)) | ||
| { | ||
| SearchBox.IsSuggestionListOpen = true; | ||
| } | ||
| } | ||
|
|
||
| private void SearchBox_KeyDown(object sender, KeyEventArgs e) | ||
| { | ||
| if (e.Key == Key.Escape) | ||
| { | ||
| ResultSelected?.Invoke(this, "__back__"); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,7 +51,8 @@ public partial class SettingsWindow : Window | |
| { "AboutPage", typeof(AboutPage) }, | ||
| { "Settings", typeof(SettingsPage) }, | ||
| { "PluginPage", typeof(PluginPage) }, | ||
| { "PluginSettingsPage", typeof(PluginSettingsPage) } | ||
| { "PluginSettingsPage", typeof(PluginSettingsPage) }, | ||
| { "SearchPage", typeof(SearchPage) } | ||
| }; | ||
| private Dictionary<string, Type> _pageTypes; | ||
| private readonly Dictionary<string, object> _pages = new Dictionary<string, object>(); | ||
|
|
@@ -112,7 +113,8 @@ public SettingsWindow() | |
| { "AboutPage", typeof(AboutPage) }, | ||
| { "Settings", typeof(SettingsPage) }, | ||
| { "PluginPage", typeof(PluginPage) }, | ||
| { "PluginSettingsPage", typeof(PluginSettingsPage) } | ||
| { "PluginSettingsPage", typeof(PluginSettingsPage) }, | ||
| { "SearchPage", typeof(SearchPage) } | ||
| }; | ||
|
|
||
| // 默认选中首页 | ||
|
|
@@ -150,10 +152,12 @@ public SettingsWindow() | |
| }; | ||
|
|
||
| AnnouncementService.UnreadCountChanged += UpdateAnnouncementUnreadBadge; | ||
| SearchPage.ResultSelected += OnSearchPageResultSelected; | ||
|
|
||
| this.Closed += (sender, e) => | ||
| { | ||
| AnnouncementService.UnreadCountChanged -= UpdateAnnouncementUnreadBadge; | ||
| SearchPage.ResultSelected -= OnSearchPageResultSelected; | ||
| UnregisterDpiChangedListener(); | ||
| _pages.Clear(); | ||
| _pageTypes.Clear(); | ||
|
|
@@ -737,6 +741,31 @@ private void OnControlsSearchBoxTextChanged(AutoSuggestBox sender, AutoSuggestBo | |
| sender.ItemsSource = suggestions; | ||
| } | ||
|
|
||
| private void OnControlsSearchBoxGotFocus(object sender, RoutedEventArgs e) | ||
| { | ||
| // 构建搜索索引并传给 SearchPage | ||
| EnsureSearchIndexBuilt(); | ||
| SearchPage.SearchData = _searchIndex | ||
| .Select(se => (se.Text, se.PageTag)) | ||
| .ToList(); | ||
| NavigateToPage("SearchPage"); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Severity: medium 🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage. |
||
| NavigationViewControl.Header = NavStrings.Nav_SearchSettings; | ||
| // 取消侧边栏选中状态 | ||
| NavigationViewControl.SelectedItem = null; | ||
| } | ||
|
|
||
| private void OnSearchPageResultSelected(object sender, string pageTag) | ||
| { | ||
| if (pageTag == "__back__") | ||
| { | ||
| // 返回上一页 | ||
| if (rootFrame.CanGoBack) rootFrame.GoBack(); | ||
| return; | ||
| } | ||
|
|
||
| NavigateToSearchEntry(_searchIndex?.FirstOrDefault(e => e.PageTag == pageTag)); | ||
| } | ||
|
|
||
| // 统一获取所有导航项(主菜单+子菜单+底部菜单) | ||
| private List<NavigationViewItem> GetAllNavigationItems() | ||
| { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the query becomes empty,
ItemsSourceis cleared butIsSuggestionListOpenisn’t explicitly closed, so the suggestion popup can remain open from a previous non-empty query (empty dropdown UI glitch).Severity: low
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.