2016年2月16日 星期二

Button

有三種方式,定義按下的行為

protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.Main);

            //一般註冊事件方式
            FindViewById<Button>(Resource.Id.button1).Click += Activity1_Click;

            //使用匿名委派
            FindViewById<Button>(Resource.Id.button1)
                .Click += delegate(object sender, EventArgs e)
            {
                //do Some things
            };

            //使用Lambada運算式
            FindViewById<Button>(Resource.Id.button1)
                .Click += (sender, e) =>
                {
                    //do Some things
                };

        }


按下按鈕後,若要跳到不同的頁面,需以intent方式進行,可參考
http://xamarinnote.blogspot.tw/2016/02/navigation.html

沒有留言:

張貼留言