本文整理汇总了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());
});
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}