2012-02-07
その18:Searchパネルから値を取得する
連載:Developer Previewでも強気で進めるMetroStyleApp超入門
Metro Style AppsにはShareの他にSearch機能があります。
Searchを使えば、アプリケーション外からアプリケーションに値を投げることができます。
挙動はこんなかんじ。
Shareと同じように、Searchパネルを表示するトグルボタンも作れます。
検索バーが出るので、テキストを入力してEnter
値がアプリ内のTextBlockに入ります。
もちろん、他のアプリケーションを開いているときでも検索できます。
Searchパネルでは検索したいアプリを選択して、検索できます。
では、実装しましょう。これも簡単です。
using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Windows.Foundation; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Data; //Searchパネルを使いたい時にUsing using Windows.ApplicationModel.Search; namespace Application24 { partial class MainPage { SearchPane searchPane; public MainPage() { InitializeComponent(); //Searchパネルのオブジェクトを作成 this.searchPane = SearchPane.GetForCurrentView(); //検索があった時のイベントを登録 this.searchPane.QuerySubmitted += new TypedEventHandler<SearchPane, SearchPaneQuerySubmittedEventArgs>(this.OnQuerySubmitted); } public void OnQuerySubmitted(object sender, SearchPaneQuerySubmittedEventArgs args) { //引数で降ってくるテキストを取得 tb.Text = args.QueryText; } private void Button_Tapped(object sender, Windows.UI.Xaml.Input.TappedEventArgs e) { //Searchパネルを表示非表示するボタン this.searchPane.Show(); } } }
<UserControl x:Class="Application24.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="1366"> <Grid x:Name="LayoutRoot" Background="#FF0C0C0C"> <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center"> <Button Tapped="Button_Tapped" Content="Show SeachPanel" Width="288" Height="100" HorizontalAlignment="Center" FontSize="30"></Button> <TextBlock Text="Seach Text" x:Name="tb" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="72"></TextBlock> </StackPanel> </Grid> </UserControl>
最後に、Package.appmanifestのDeclarationsから、Searchパネルの利用を許可します。
これがないとビルドが通りません。
ところで、なんで形名がSearchPaneなんやろう。。。
これ絶対たいぽやとおもうねんけど(
追記:これペインってよむんだって!ありがとうございます!
http://eow.alc.co.jp/search?q=pane&ref=sa
英語よわいんがばれる。。。。!
トラックバック - http://d.hatena.ne.jp/c-mitsuba/20120207/1328616310
リンク元
- 29 http://d.hatena.ne.jp/is01next/20120125/1327500968
- 28 http://android.dtmm.co.jp/device/4862
- 24 http://longurl.org
- 12 http://d.hatena.ne.jp/is01next/
- 9 http://www.google.com/search
- 8 http://www.rairaiken.org/?p=1553
- 6 http://d.hatena.ne.jp
- 6 http://t.co/Z1cjc8qd
- 5 http://www.google.co.jp/url?sa=t&rct=j&q=メタセコイア mac&source=web&cd=2&ved=0CDcQFjAB&url=http://d.hatena.ne.jp/c-mitsuba/20090630/1246293984&ei=CwkzT6vQEM-MmQWUrqnEBQ&usg=AFQjCNH5m3bkmConFUa
- 5 http://www.google.co.jp/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0CCYQFjAA&url=http://d.hatena.ne.jp/c-mitsuba/20120126/1327504265&ei=tG4zT4exOOf6mAWN06GnAg&usg=AFQjCNENcGa1SyaJK3JU-ln45w8k-vfINw&sig2=fRK4u9RJbVJcSOFqK7PNRg






