【发布时间】:2018-10-05 14:15:53
【问题描述】:
我为测试目的制作了一个 Xamarin 应用程序,出于某种原因,我添加的按钮不会触发该命令。我也尝试过从代码隐藏和 xaml 设置上下文,但它仍然不起作用。
XAML 代码:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:implementation="clr-namespace:RxposTestApp.Implementation;assembly=RxposTestApp"
x:Class="RxposTestApp.Page">
<ContentPage.BindingContext>
<implementation:BaseCommandHandler/>
</ContentPage.BindingContext>
<ContentPage.Content>
<StackLayout>
<Label Text="Welcome to Xamarin.Forms!"
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand" />
<Button Text="CLIK MIE" Command="BaseCommand"/>
</StackLayout>
</ContentPage.Content>
</ContentPage>
BaseCommandHandler 类:
public class BaseCommandHandler : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public ICommand BaseCommand { get; set; }
public BaseCommandHandler()
{
BaseCommand = new Command(HandleCommand);
}
public void HandleCommand()
{
//should fire this method
}
}
【问题讨论】:
标签: xamarin button command click