6 August 2011 0 Comments

WP7.5 でリストボックスのスクロールエンドで圧縮されるときのイベントを取る

Windows Phone のリストボックスでは、上下にスクロールしたのち端まで行くと一瞬圧縮されます。アプリケーションによってはこれをトリガーにしているアプリケーションもあります。 Windows Phone 7.5(Mango)では、この瞬間を(直接ではないですが)イベントとして取得する事ができます。 ■Mangoにはスクロール圧縮が状態定義されている! からくりを一言でいうと、Windows Phone 7.5(Mango)では、ScrollViewerのVisualStateに"Scrolling"や"NotScrolling"以外に、以下のVisualStateが定義されているのです。 VerticalCompression VisualStateGroup CompressionTop CompressionBottom NoVerticalCompression HorizontalCompression VisualStateグループ CompressionLeft CompressionRight NoHorizontalCompression つまり、このVisualStateGroupの変化を取得し、その時の状態を確認してみればスクロールエンドの状態を取得する事ができるのです。 そして、 ListboxはVisualTreeを紐解けば(中の構造を開いてみると)ScrollViewer が使われています。 ですから、Listboxのスクロールエンドの状態ももちろん取り出すことができます。 ■処理の流れ 手順はこんな感じ VisualStateが把握できるよう再定義 ListboxからScrollViewerを取り出す ScrollViewerからVisualStateGroupを取り出す VisualStateGroupの変化に対するイベントを取得(CurrentStateChanging) VisualStateの状態を見て必要なState(例 CompressionTop)に合わせて処理を実行する という感じ。   ■実装してみよう まずは新しくプロジェクトを作ってみます。DataBound Application が簡単でしょうね。 ① VisualStateの再定義 そして、MainPage.Xaml の17行目あたりに以下のVisualStateの再定義コードを追加(1) 複雑に見えますが、デフォルトのScrollViewerとの定義の違いは青い部分だけ。 <phone:PhoneApplicationPage.Resources>     <Style TargetType="ScrollViewer">         <Setter Property="VerticalScrollBarVisibility" Value="Auto"/>         <Setter Property="HorizontalScrollBarVisibility" Value="Disabled"/>         <Setter Property="Background" Value="Transparent"/>         <Setter Property="Padding" Value="0"/>         <Setter Property="BorderThickness" Value="0"/>         <Setter Property="BorderBrush" Value="Transparent"/>         <Setter Property="Template">             <Setter.Value>                 <ControlTemplate TargetType="ScrollViewer">                     <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}">                         <VisualStateManager.VisualStateGroups>                             <VisualStateGroup x:Name="ScrollStates">                                 <VisualStateGroup.Transitions>                                     <VisualTransition GeneratedDuration="00:00:00.5"/>                                 </VisualStateGroup.Transitions>                                 <VisualState x:Name="Scrolling">                                     <Storyboard>                                         <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="VerticalScrollBar"/>                                         <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="HorizontalScrollBar"/>                                     </Storyboard>                                 </VisualState>                                 <VisualState x:Name="NotScrolling"/>                             </VisualStateGroup>                             <VisualStateGroup x:Name="VerticalCompression">                                 <VisualState x:Name="NoVerticalCompression"/>                                 <VisualState x:Name="CompressionTop"/>                                 <VisualState x:Name="CompressionBottom"/>                             </VisualStateGroup>                             <VisualStateGroup x:Name="HorizontalCompression">                                 <VisualState x:Name="NoHorizontalCompression"/>                                 <VisualState x:Name="CompressionLeft"/>                                 <VisualState x:Name="CompressionRight"/>                             </VisualStateGroup>                         </VisualStateManager.VisualStateGroups>                         <Grid Margin="{TemplateBinding Padding}">                             <ScrollContentPresenter x:Name="ScrollContentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}"/>                             <ScrollBar x:Name="VerticalScrollBar" HorizontalAlignment="Right" Height="Auto" IsHitTestVisible="False" IsTabStop="False" Maximum="{TemplateBinding ScrollableHeight}" Minimum="0" Opacity="0" Orientation="Vertical" Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}" Value="{TemplateBinding VerticalOffset}" ViewportSize="{TemplateBinding ViewportHeight}" VerticalAlignment="Stretch" Width="5"/>                             <ScrollBar x:Name="HorizontalScrollBar" HorizontalAlignment="Stretch" Height="5" IsHitTestVisible="False" IsTabStop="False" Maximum="{TemplateBinding ScrollableWidth}" Minimum="0" Opacity="0" Orientation="Horizontal" Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}" Value="{TemplateBinding HorizontalOffset}" ViewportSize="{TemplateBinding ViewportWidth}" VerticalAlignment="Bottom" Width="Auto"/>                         </Grid>                     </Border>                 </ControlTemplate>             </Setter.Value>         </Setter>     </Style> </phone:PhoneApplicationPage.Resources>   ② VisualStateの変化をハンドリング 続けて、MainPage.xaml.cs に、ListboxからScrollViewerを取り出し、その中のVisualStateの変化をハンドリングする関数を追加 private void ListBoxCompressionHandling(ListBox targetlistbox) {     VisualStateGroup vgroup = new VisualStateGroup();     // ListBox の初めに定義されている ScrollViewerを取り出す     ScrollViewer ListboxScrollViewer = (ScrollViewer)VisualTreeHelper.GetChild(targetlistbox, 0);     // Visual State はコントロールテンプレートの常に最上位に定義されている     FrameworkElement element = (FrameworkElement)VisualTreeHelper.GetChild(ListboxScrollViewer, 0);     // Visual State を取り出しその中から 縦横Compression のVisualStateを取り出す     foreach (VisualStateGroup group in VisualStateManager.GetVisualStateGroups(element))         if (group.Name == "VerticalCompression") vgroup = group;     //縦横Compressionの状態が変わった時のイベントハンドラ     vgroup.CurrentStateChanging += new EventHandler<VisualStateChangedEventArgs>(ScrollViewer_CurrentStateChanging); } ③ イベント発生時の処理はご自由に♪ void ScrollViewer_CurrentStateChanging(object sender, VisualStateChangedEventArgs e) {     ApplicationTitle.Text = e.NewState.Name; //switch (e.NewState.Name) //{ //    case "CompressionTop": //        break; //    case "CompressionBottom": //        break; //    case "NoVerticalCompression": //        break; //    default: //        break; //} }   ④ Listboxとの紐づけ 最後に、おなじく、MainPage.xaml.cs の中の MainPage_Loaded イベントの中で、リストボックスをハンドリングするように、作成した関数を呼ぶ。 private void MainPage_Loaded(object sender, RoutedEventArgs e) { :     ListBoxCompressionHandling(MainListBox); }   ■まとめ 以上で完了です。Xamlの定義と、ListBoxCompressionHandling 関数だけコピペして使えば、簡単に利用できますし、ScrollViewerで使えば、縦以外に横のスクロールエンドも定義できます。

4 July 2011 0 Comments

「C++ による Windows プログラミングの学習」 が日本語化されました

みなさん、こんにちは。Windows 開発統括部の古内です。 C++ 初心者の方を対象とした MSDN ライブラリの 「 Learn to Program for Windows in C++ 」 がこのたび日本語化され、 「 C++ による Windows プログラミングの学習 」 として公開されました。こちらの内容は、以前ご案内した 「 Hilo プロジェクト 」 のページからもリンクされています。本来であれば、まず 「 C++ による Windows プログラミングの学習 」 で基本を押さえてから、「 Hilo: Windows 7 対応 C++ アプリケーションの開発 」 で応用を学んでいただく、という順序で読んでいただくべきですが、翻訳の順番が逆になってしましました。 スミマセン。 内容は以下のとおりです。ぜひご活用ください。 Windows C++ プログラミングの概要 開発環境を準備する Windows におけるコーディング規約 文字列を使用する ウィンドウとは WinMain: アプリケーション エントリ ポイント モジュール 1.

20 June 2011 0 Comments

Fuel Tracker sample application for WP7 now in Visual Basic

I’m happy to report that the Fuel Tracker sample  is now available in Visual Basic. Additionally, we have fixed several small issues that various people have reported, one of which prevented the application from working correctly when running under the Windows Phone Developer Tools 7.1 Beta . The accompanying documentation has not yet been updated, but will be in the near future

1 June 2011 0 Comments

Приложения Windows Phone 7 Apps на максимальной скорости

  Грег Дункан Баа…Производительность и оптимизация уже надоели. Что в них интересного? Иметь приложение, которое работает хорошо не прикольно, это полный восторг

24 March 2011 0 Comments

Four Bros Studio has released Volume 1 of Taptitude on WP7 Marketplace

  My first XNA game for Windows Phone 7 is out the door.  One thing that is nice about XNA is that I was able to leverage a ton of code from my previous Xbox 360 game (Wayne The Brain).  This time around we decided to do a collection of mini-games with online leaderboards.  Taptitude is the name of the collection and Taptitude: Volume 1 contains the first 5 mini games. Screenshots: http://wpappshub.com/games/taptitude-volume-1 Description: A collection of five competitive mini-games that are sure to test your skills

5 March 2011 0 Comments

Díl 2 – Instalace Kodu a malý průzkum

Nároky na PC Kodu vám poběží na operačních systémech Windows XP, Windows Vista i Windows 7. Dále je třeba počítat s tím, že budete potřebovat grafickou kartu, která podporuje DirectX9 a Shader Model 2.0 nebo vyšší. (Jak již bylo uvedeno v 1.díle Kodu si můžete stáhnout například z www.DreamSpark.com nebo z http://research.microsoft.com/en-us/projects/kodu/ ) Jak zjistím verzi DirectX

26 February 2011 0 Comments

Visual Basic Windows Phone 7 Series: How to create a custom indeterminate progress bar application for Windows Phone 7

In our last post , I explained how to create a microphone for Windows Phone 7. In this blog, I want to share a sample that will help you to create a custom indeterminate progress bar for Windows Phone 7. You can create an indeterminate progress bar that runs on the UI thread, but that can impact the performance of your application.

Tags: , , , , , , , ,
15 February 2011 0 Comments

모다의 윈도우폰7 뚝딱 팩토리(10)-가속도계(중력센서) 사용하기

    한국마이크로소프트에서 초급 스마트폰 개발자 분들을 위해 공개하는 모다의 윈도우폰7 뚝딱 팩토리 열번째 영상! 윈도우폰 표준안 에는 중력센서라고도 알려져 있는 ‘가속도계(accelerometer)’가 탑재되어있습니다.

13 February 2011 0 Comments

The Latest Love of My (Programming) Life?

Is it really possible to love jQuery? It certainly seems like it is from the numerous blog and forum posts I’ve read while trying to figure out how to make it do some fairly simple things.

9 February 2011 0 Comments

모다의 윈도우폰7 뚝딱 팩토리(3)-윈도우폰7의 UI 구성요소(Controls)

  모다의 윈도우폰7 뚝딱 팩토리(3)-윈도우폰7의 UI 구성요소(Controls)   한국마이크로소프트에서 초급 스마트폰 개발자 분들을 위해 공개하는 모다의 윈도우폰7 뚝딱 팩토리 세번째 영상! 윈도우폰의 UI를 구성하는 컨트롤에 대해서 알아보고 버튼을 추가하며, 이를 이용해 페이지 전환예제를 구현합니다.   이번 예제에서 사용된 예제 소스코드는 아래를 참고해주세요.   using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using Microsoft.Phone.Controls; namespace navigation {     public partial class MainPage : PhoneApplicationPage     {         // Constructor         public MainPage()         {             InitializeComponent();         }         private void button1_Click(object sender, RoutedEventArgs e)         {             MessageBox.Show("Navigation");         }         private void hyperlinkButton1_Click(object sender, RoutedEventArgs e)         {             NavigationService.Navigate(new Uri("/Page1.xaml", UriKind.RelativeOrAbsolute));         }     } }   동영상 보러가기 슬라이드 보러가기 윈도우폰7 공식 팬페이지

8 February 2011 0 Comments

Windows Identity Foundation (WIF) January 2011 Update released with lots of new exercises and sample

On January 24th 2011, Windows Azure Team,  released an update to the Identity Developer Training Kit . Windows Azure Team also released the first MSDN-hosted Identity Developer Training Course , an online version of the kit where all the labs instructions and setup files are unbundled and individually accessible. Windows Identity Foundation Guru Vittorio Bertocci also blogged about this announcement  here

6 February 2011 0 Comments

WPF kostenfrei lernen

Der Einstieg in WPF (Windows Presentation Foundation) ist sehr einfach und darüber hinaus auf völlig kostenfrei möglich, wenn man mal von den Gebühren für die Internetleitung und die Abnutzung des eigenen PCs absieht. Zum einen bekommt man ja das Werkzeug Visual Studio 2010 Express kostenfrei hier zum Download