Xaml-searchbox
XAML-SearchBox
SearchBoxは、検索クエリテキストの入力に使用できるコントロールを表します。 WPFプロジェクトはSearchBoxをサポートしていないため、Windowsアプリに実装されます。 SearchBoxクラスの階層的な継承は次のとおりです-
プロパティ
以下に、SearchBoxクラスの一般的に使用されるプロパティを示します。
Sr.No. | Property & Description |
---|---|
1 |
PlaceholderText ユーザーアクションまたはその他の操作によって値が変更されるまで、コントロールに表示されるテキストを取得または設定します。 |
2 |
ChooseSuggestionOnEnter ユーザーがEnterキーを押したときに提案された検索クエリがアクティブになるかどうかを決定する値を取得または設定します。 |
3 |
ChooseSuggestionOnEnterProperty ChooseSuggestionOnEnter依存プロパティを識別します。 |
4 |
FocusOnKeyboardInput ユーザーがアプリの任意の場所を入力して検索できるかどうかを決定する値を取得または設定します。 |
5 |
FocusOnKeyboardInputProperty FocusOnKeyboardInput依存プロパティを識別します。 |
6 |
PlaceholderTextProperty PlaceholderText依存プロパティを識別します。 |
7 |
QueryText 検索ボックスのテキストコンテンツを取得または設定します。 |
8 |
QueryTextProperty QueryText依存プロパティを識別します。 |
9 |
SearchHistoryContext 検索のコンテキストを識別する文字列を取得または設定し、アプリでのユーザーの検索履歴の保存に使用されます。 |
10 |
SearchHistoryContextProperty SearchHistoryContext依存プロパティを識別します。 |
11 |
SearchHistoryEnabled 検索履歴から検索候補が作成されるかどうかを決定する値を取得または設定します。 |
12 |
SearchHistoryEnabledProperty SearchHistoryEnabled依存プロパティを識別します。 |
イベント
以下に、SearchBoxで一般的に使用されるイベントを示します。
Sr.No. | Event & Description |
---|---|
1 |
PrepareForFocusOnKeyboardInput FocusOnKeyboardInputプロパティがtrueで、アプリがテキストキーボード入力を受け取ったときに発生します。 |
2 |
QueryChanged クエリテキストが変更されたときに発生します。 |
3 |
QuerySubmitted ユーザーが検索クエリを送信すると発生します。 |
4 |
ResultSuggestionChosen ユーザーが提案された検索結果を選択したときに発生します。 |
5 |
SuggestionsRequested ユーザーのクエリテキストが変更され、アプリが検索ペインに表示する新しい提案を提供する必要がある場合に発生します。 |
方法
以下に、SearchBoxで一般的に使用されるメソッドを示します。
Sr.No. | Method & Description |
---|---|
1 |
OnManipulationCompleted ManipulationCompletedイベントが発生する前に呼び出されます。 (Controlから継承) |
2 |
OnManipulationDelta ManipulationDeltaイベントが発生する前に呼び出されます。 (Controlから継承) |
3 |
OnManipulationInertiaStarting ManipulationInertiaStartingイベントが発生する前に呼び出されます。 (Controlから継承) |
4 |
OnManipulationStarted ManipulationStartedイベントが発生する前に呼び出されます。 (Controlから継承) |
5 |
OnManipulationStarting ManipulationStartingイベントが発生する前に呼び出されます。 (Controlから継承) |
6 |
OnMaximumChanged Maximumプロパティが変更されたときに呼び出されます。 (RangeBaseから継承) |
7 |
OnMinimumChanged Minimumプロパティが変更されたときに呼び出されます。 (RangeBaseから継承) |
8 |
OnValueChanged ValueChangedルーティングイベントを発生させます。 (RangeBaseから継承) |
9 |
SetBinding 提供されたバインディングオブジェクトを使用して、FrameworkElementにバインディングをアタッチします。 (FrameworkElementから継承されます) |
10 |
SetLocalContentSuggestionSettings ローカルファイルに基づく提案を検索ボックスの提案に自動的に表示するかどうかを指定し、Windowsがこれらの提案を見つけてフィルタリングするために使用する基準を定義します。 |
11 |
SetValue DependencyObjectの依存関係プロパティのローカル値を設定します。 (DependencyObjectから継承) |
12 |
StartDragAsync ドラッグアンドドロップ操作を開始します。 (UIElementから継承) |
13 |
UnregisterPropertyChangedCallback RegisterPropertyChangedCallbackを呼び出して、以前に登録された変更通知をキャンセルします。 (DependencyObjectから継承) |
例
次の例は、XAMLアプリケーションでのSearchBoxの使用法を示しています。 いくつかのプロパティとイベントを使用してSearchBoxを作成および初期化するXAMLコードを次に示します。
<Page x:Class = "XAML_SearchBox.MainPage"
xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x = "http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local = "using:XAML_SearchBox"
xmlns:d = "http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc = "http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable = "d">
<Grid Background = "{ThemeResource ApplicationPageBackgroundThemeBrush}">
<SearchBox x:Name = "mySearchBox"
FocusOnKeyboardInput = "False"
QuerySubmitted = "mySearchBox_QuerySubmitted"
Height = "35" Width = "400" Margin = "234,132,732,601"/>
</Grid>
</Page>
検索クエリのC#での実装は次のとおりです-
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.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
//The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
namespace XAML_SearchBox {
///<summary>
///An empty page that can be used on its own or navigated to within a Frame.
///</summary>
public sealed partial class MainPage : Page {
public MainPage() {
this.InitializeComponent();
}
private void mySearchBox_QuerySubmitted(SearchBox sender,
SearchBoxQuerySubmittedEventArgs args) {
this.Frame.Navigate(typeof(SearchResultsPage1), args.QueryText);
}
}
}
この例のWindowsアプリプロジェクトでは、 SearchResultsPage1.xaml という名前の*検索結果ページ*を追加します。 このアプリを実行するには、デフォルトの実装で十分です。
上記のコードをコンパイルして実行すると、次の出力が生成されます-
上記のサンプルコードを実行し、他のいくつかのプロパティとイベントを試すことをお勧めします。