Created
August 28, 2012 06:51
-
-
Save tateisu/3495651 to your computer and use it in GitHub Desktop.
AlertDialogBuilderぽいものを作ってみた
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
using jp.juggler.util.dialog; | |
using System.Diagnostics; | |
using System.Windows.Threading; | |
namespace TestAlertDialog { | |
public partial class MainPage : PhoneApplicationPage { | |
const String dialog_title = "テスト"; | |
// コンストラクター | |
public MainPage() { | |
InitializeComponent(); | |
btnTestAlertDialog.Click += (sender,e) => { | |
new AlertDialogBuilder{ | |
Title = dialog_title | |
,Message="テストする項目を選んで下さい\nテストする項目を選んで下さい\nテストする項目を選んで下さい\nテストする項目を選んで下さい\nテストする項目を選んで下さい" | |
,Vertical= true | |
,CheckBoxText="特に意味のないチェックボックス" | |
}.SetActions( | |
new AlertDialogAction("全くパラメータを指定しない場合", ()=>{ | |
new AlertDialogBuilder().Show(); | |
}) | |
,new AlertDialogAction("キャンセル可能なダイアログ",()=>{ | |
new AlertDialogBuilder{ | |
Title = dialog_title | |
,Message="このダイアログにはボタンがありませんが、戻るボタンで閉じることができます" | |
,Actions = null | |
}.Show(); | |
}) | |
,new AlertDialogAction("キャンセル不可なダイアログ",()=>{ | |
new AlertDialogBuilder{ | |
Title = dialog_title | |
,Message="このダイアログは戻るボタンに反応しません" | |
,Cancellable = false | |
}.Show(); | |
}) | |
,new AlertDialogAction("キャンセルの有無をチェック",()=>{ | |
new AlertDialogBuilder{ | |
Title = dialog_title | |
,Message="ボタンを押すか、戻るキーを押すか" | |
,CloseAction = (bCancelled,bChecked)=>{ | |
new AlertDialogBuilder { | |
Title = dialog_title | |
,Message=( bCancelled? "キャンセルされました" : "Closeが押されました") | |
}.Show(); | |
} | |
}.Show(); | |
}) | |
,new AlertDialogAction( "チェックボックス(初期ON)",() => { | |
new AlertDialogBuilder{ | |
Title = dialog_title | |
,Message = "チェックボックスのついたダイアログ(初期ON)" | |
,CheckBoxText="チェックボックス" | |
,CheckBoxChecked = true | |
,CloseAction = (bCancelled,bChecked)=>{ | |
var msg = String.Format( "cancelled={0} checked={1}",bCancelled,bChecked ); | |
new AlertDialogBuilder{ | |
Title = dialog_title | |
,Message = msg | |
}.Show(); | |
} | |
}.Show(); | |
}) | |
,new AlertDialogAction( "チェックボックス(初期OFF)",() => { | |
new AlertDialogBuilder{ | |
Title = dialog_title | |
,Message = "チェックボックスのついたダイアログ(初期OFF)" | |
,CheckBoxText="チェックボックス" | |
,CheckBoxChecked = false | |
,CloseAction = (bCancelled,bChecked)=>{ | |
var msg = String.Format( "cancelled={0} checked={1}",bCancelled,bChecked ); | |
new AlertDialogBuilder{ | |
Title = dialog_title | |
,Message = msg | |
}.Show(); | |
} | |
}.Show(); | |
}) | |
,new AlertDialogAction( "ボタンの有効/無効",() => { | |
var action = new AlertDialogAction( "TEST",null ); | |
var timer = new DispatcherTimer(); | |
timer.Interval = TimeSpan.FromSeconds( 5 ); | |
timer.Tick += ( a,b ) => { | |
action.Enabled = !action.Enabled; | |
action.Content = ( action.Enabled ? "有効" :"無効" ); | |
}; | |
timer.Start(); | |
new AlertDialogBuilder { | |
Title = dialog_title, | |
Message = "一定時間でボタンの有効/無効が切り替わります", | |
CloseAction = ( bCancelled,bChecked ) => { timer.Stop(); } | |
}.SetActions( action ).Show(); | |
} ) | |
,new AlertDialogAction( "AAAAAAAAAAAAAA",null ) | |
,new AlertDialogAction( "AAAAAAAAAAAAAA",null ) | |
,new AlertDialogAction( "AAAAAAAAAAAAAA",null ) | |
,new AlertDialogAction( "AAAAAAAAAAAAAA",null ) | |
,new AlertDialogAction( "AAAAAAAAAAAAAA",null ) | |
,new AlertDialogAction( "AAAAAAAAAAAAAA",null ) | |
,new AlertDialogAction( "AAAAAAAAAAAAAA",null ) | |
,new AlertDialogAction( "AAAAAAAAAAAAAA",null ) | |
,new AlertDialogAction( "AAAAAAAAAAAAAA",null ) | |
,new AlertDialogAction( "AAAAAAAAAAAAAA",null ) | |
,new AlertDialogAction( "AAAAAAAAAAAAAA",null ) | |
,new AlertDialogAction( "AAAAAAAAAAAAAA",null ) | |
,new AlertDialogAction( "AAAAAAAAAAAAAA",null ) | |
,new AlertDialogAction( "AAAAAAAAAAAAAA",null ) | |
) | |
.Show(); | |
}; | |
} | |
void checkboxed_dialog_test(bool checkbox_checked_before,string msg){ | |
new AlertDialogBuilder{ | |
Title = "チェックボックスつきダイアログのテスト" | |
,Message = msg | |
,CheckBoxText = "チェックボックステキスト" | |
,CheckBoxChecked = checkbox_checked_before | |
,Vertical = checkbox_checked_before | |
,CloseAction = ( bCancelled,bChecked ) => { | |
if( bCancelled ){ | |
new AlertDialogBuilder{ | |
Title = "結果" | |
,Message = "キャンセルされたので、チェックボックスの値の変更は無視されます" | |
} | |
.SetActions( AlertDialogAction.ACTION_OK ) | |
.Show(); | |
} else if( checkbox_checked_before != bChecked ) { | |
new AlertDialogBuilder{ | |
Title = "結果" | |
,Message = "チェックボックスの値は変更されました" | |
} | |
.SetActions( AlertDialogAction.ACTION_CLOSE ) | |
.Show(); | |
} else { | |
new AlertDialogBuilder{ | |
Title = "結果" | |
,Message = "チェックボックスの値は変更されませんでした" | |
} | |
.SetActions( AlertDialogAction.ACTION_CLOSE ) | |
.Show(); | |
} | |
} | |
} | |
.SetActions( | |
new AlertDialogAction( "A",null ) | |
,new AlertDialogAction( "B",null ) | |
,new AlertDialogAction( "C",null ) | |
) | |
.Show(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment