当前位置: 首页>>代码示例>>C#>>正文


C# Button.SetCommand方法代码示例

本文整理汇总了C#中Button.SetCommand方法的典型用法代码示例。如果您正苦于以下问题:C# Button.SetCommand方法的具体用法?C# Button.SetCommand怎么用?C# Button.SetCommand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Button的用法示例。


在下文中一共展示了Button.SetCommand方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnCreate

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

           
            // Get our button from the layout resource,
            // and attach an event to it
            ButtonGet = FindViewById<Button>(Resource.Id.myButton);
            UsernameText = FindViewById<EditText>(Resource.Id.username);
            PasswordText = FindViewById<EditText>(Resource.Id.password);
            ComboText = FindViewById<TextView>(Resource.Id.combo);
            ProgressBar = FindViewById<ProgressBar>(Resource.Id.progressBar1);


            //So things don't link out. 
            //Only needed if linking all
            //UsernameText.TextChanged += (sender, e) => {};
            //PasswordText.TextChanged += (sender, e) => {};
            //ButtonGet.Click += (sender, e) => {};

            ButtonGet.SetCommand("Click", VM.GetPeopleCommand);

            unBind = this.SetBinding(() => VM.Username, 
                () => UsernameText.Text,
                BindingMode.TwoWay);

            passBind = this.SetBinding(() => VM.Password, 
                () => PasswordText.Text,
                BindingMode.TwoWay);

            combBind = this.SetBinding(() => VM.ComboDisplay,
                () => ComboText.Text,
                BindingMode.OneWay);

            busyBind = this.SetBinding(() => VM.IsBusy).WhenSourceChanges(() =>
                {
                    ButtonGet.Enabled = !VM.IsBusy;
                    if(VM.IsBusy)
                        ProgressBar.Visibility = ViewStates.Visible;
                    else
                        ProgressBar.Visibility = ViewStates.Invisible;
                });

            updatedBind = this.SetBinding(() => VM.People)
                .WhenSourceChanges(() =>
                    {
                        RunOnUiThread(() =>Toast.MakeText(this, "Count: " + VM.People.Count, ToastLength.Short).Show()); 

                    });
        }
开发者ID:jv9,项目名称:MotzCodesLive,代码行数:53,代码来源:MainActivity.cs

示例2: SetCommand_OnButtonNoValueNoEventName_ClickEventShouldBeUsed

        public void SetCommand_OnButtonNoValueNoEventName_ClickEventShouldBeUsed()
        {
            var value = DateTime.Now.Ticks.ToString();
            var vmTarget = new TestViewModel();
            vmTarget.Configure(value);

            var button = new Button(Application.Context);

            button.SetCommand(vmTarget.SetPropertyWithoutValueCommand);

            Assert.IsNull(vmTarget.TargetProperty);
            button.PerformClick();
            Assert.AreEqual(value, vmTarget.TargetProperty);
        }
开发者ID:NulledLabs,项目名称:mvvmlight,代码行数:14,代码来源:SetCommandTest.cs

示例3: OnCreate

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            if (!_isInitialized)
            {
                var nav = new MvvmLightNavigationExtension.Droid.NavigationServiceExtension();
                nav.Initialize();
                nav.Configure("Page1", typeof(MainActivity));
                nav.Configure("Page2", typeof(PageActivity));
                nav.Configure("Page3", typeof(Page3Activity));

                var builder = new ContainerBuilder();
                builder.RegisterInstance<INavigationService>(nav);
                builder.RegisterInstance<INavigationServiceExtension>(nav);

                var container = builder.Build();

                ServiceLocator.SetLocatorProvider(() => new AutofacServiceLocator(container));

                _isInitialized = true;

                ViewModel = new MainViewModel();
            }

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            // Get our button from the layout resource,
            // and attach an event to it
            _button = FindViewById<Button>(Resource.Id.MyButton);
            _button.SetCommand("Click", ViewModel.Goto);

            _button = FindViewById<Button>(Resource.Id.MyButton2);
            _button.SetCommand("Click", ViewModel.GotoWithParameter);

            _button.Click += _button_Click;
        }
开发者ID:dhindrik,项目名称:MvvmLightNavigationExtension,代码行数:38,代码来源:MainActivity.cs

示例4: SetCommand_OnButtonWithBinding_ParameterShouldUpdate

        public void SetCommand_OnButtonWithBinding_ParameterShouldUpdate()
        {
            var value = DateTime.Now.Ticks.ToString();

            var vmSource = new TestViewModel
            {
                Model = new TestModel
                {
                    MyProperty = value
                }
            };

            var vmTarget = new TestViewModel();

            var button = new Button(Application.Context);

            var binding = new Binding<string, string>(
                vmSource,
                () => vmSource.Model.MyProperty);

            button.SetCommand(
                "Click",
                vmTarget.SetPropertyCommand,
                binding);

            Assert.IsNull(vmTarget.TargetProperty);
            button.PerformClick();
            Assert.AreEqual(value, vmTarget.TargetProperty);

            value += "Test";
            vmSource.Model.MyProperty = value;
            button.PerformClick();
            Assert.AreEqual(value, vmTarget.TargetProperty);
        }
开发者ID:NulledLabs,项目名称:mvvmlight,代码行数:34,代码来源:SetCommandTest.cs

示例5: SetCommand_WithICommandOnButtonNoValueNoEventName_ClickEventShouldBeUsed

        public void SetCommand_WithICommandOnButtonNoValueNoEventName_ClickEventShouldBeUsed()
        {
            var vmTarget = new TestViewModel();
            var button = new Button(Application.Context);

            button.SetCommand(vmTarget.TestCommandImpl);

            var castedCommand = (CommandImpl)vmTarget.TestCommandImpl;

            Assert.IsNull(castedCommand.Parameter);
            button.PerformClick();
            Assert.AreEqual(TestViewModel.ValueForCommand, castedCommand.Parameter);
        }
开发者ID:NulledLabs,项目名称:mvvmlight,代码行数:13,代码来源:SetCommandTest.cs

示例6: SetCommand_OnButtonWithSimpleValue_NoError

        public void SetCommand_OnButtonWithSimpleValue_NoError()
        {
            var value = DateTime.Now.Ticks.ToString();
            var vmTarget = new TestViewModel();

            var button = new Button(Application.Context);

            button.SetCommand(
                "Click",
                vmTarget.SetPropertyCommand,
                value);

            Assert.IsNull(vmTarget.TargetProperty);
            button.PerformClick();
            Assert.AreEqual(value, vmTarget.TargetProperty);
        }
开发者ID:NulledLabs,项目名称:mvvmlight,代码行数:16,代码来源:SetCommandTest.cs


注:本文中的Button.SetCommand方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。