WP 7ステップアップテクニックカスタムToastヒントアニメーション効果

6981 ワード

Coding4Fun.Phone.Toolkitというライブラリはよく知っているでしょう.中にはToastPromptがローカルのToast方式のヒントを提供していて、とても実用的です.私のこの文章WP 7アプリケーション開発ノート(16)ローカルToastヒントを参考にすることができます.
しかし、ToastPromptの効果は簡単で、拡張が必要な場合は面倒ですが、新浪微博のようなToastをどのようにシミュレートするかを説明します.
 
やる前にまずSLのシミュレーション効果を見てみましょう.
閲覧できません.直接ダウンロード例http://files.cnblogs.com/kiminozo/ToastPromptDemo.rarをダウンロードしてください.
  
DialogServiceについて
Coding 4 Funのソースコードを表示します.主にDialogServiceクラスを使用して実装されています.
http://blogs.claritycon.com/kevinmarshall/2010/10/13/wp7-page-transitions-sample/
DialogServiceのソースコードはBlogにダウンロードしてください
 
重要なメンバーは
AnimationTypeアニメーションタイプ
Childコンテナ内のコントロール用
IsBackKeyOverrideが後退キーを上書きしているかどうか
Overlayは色を上書きし、nullの場合はタッチ操作に影響しません.
Opened、Closedイベント
Show()、Hide()表示、非表示
 
DialogServiceの変更
カスタム効果が必要な場合はCoding 4 Funのソースコードを変更する必要があります.
http://coding4fun.codeplex.com/releases/view/79749へダウンロードしてください.
 
追加効果で最も重要なのはAnimationTypeの追加です
デフォルトは2種類のSlideのみで、Coding 4 Funコードには2種類のSlideHorizontalが追加されています
列挙は以下の通りである.
public enum AnimationTypes 
{
Slide,
SlideHorizontal,
Swivel,
SwivelHorizontal,
Vetical//new
}

必要な効果を実現するために、Veticalというアニメーションタイプを追加しました.
 
このタイプに2つのStoryboardを追加
private const string VeticalInStoryboard = 
@"<Storyboard xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty=""(UIElement.RenderTransform).(TranslateTransform.Y)"">
<EasingDoubleKeyFrame KeyTime=""0"" Value=""-50""/>
<EasingDoubleKeyFrame KeyTime=""0:0:2"" Value=""0"">
<EasingDoubleKeyFrame.EasingFunction>\
<ExponentialEase EasingMode=""EaseInOut"" Exponent=""6""/>
</EasingDoubleKeyFrame.EasingFunction>
</EasingDoubleKeyFrame>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimation Storyboard.TargetProperty=""(UIElement.Opacity)"" From=""0"" To=""1"" Duration=""0:0:2""
Storyboard.TargetName=""LayoutRoot"">
<DoubleAnimation.EasingFunction>
<ExponentialEase EasingMode=""EaseOut"" Exponent=""6""/>
</DoubleAnimation.EasingFunction>
</DoubleAnimation>
</Storyboard>
";

private const string VeticalOutStoryboard =
@"<Storyboard xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty=""(UIElement.RenderTransform).(TranslateTransform.Y)"">
<EasingDoubleKeyFrame KeyTime=""0"" Value=""0""/>
<EasingDoubleKeyFrame KeyTime=""0:0:1"" Value=""-50"">
<EasingDoubleKeyFrame.EasingFunction>\
<ExponentialEase EasingMode=""EaseInOut"" Exponent=""6""/>
</EasingDoubleKeyFrame.EasingFunction>
</EasingDoubleKeyFrame>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimation Storyboard.TargetProperty=""(UIElement.Opacity)"" From=""1"" To=""0"" Duration=""0:0:1""
Storyboard.TargetName=""LayoutRoot"">
<DoubleAnimation.EasingFunction>
<ExponentialEase EasingMode=""EaseIn"" Exponent=""6""/>
</DoubleAnimation.EasingFunction>
</DoubleAnimation>
</Storyboard>
";

Show()のコードを見つけ、switchに追加
case AnimationTypes.Vetical: 
storyboard = XamlReader.Load(VeticalInStoryboard) as Storyboard;
_overlay.RenderTransform = new TranslateTransform();
break;

Hide()同理
 
それからCoding 4 FunのToastPromptクラスを見つけて、Show()の中の
AnimationType = DialogService.AnimationTypes.Vetical,

 
次のようになります.
public void Show() 
{
..

dialogService = new DialogService
{
AnimationType = DialogService.AnimationTypes.Vetical,
Child = this,
IsBackKeyOverride = true
};

...

}

 
もちろん,オブジェクト向けの知識多態化ToastPromptも利用できるが,ここでは詳細には述べない.