数据事件绑定和获取
https://learn.microsoft.com/en-us/dotnet/maui/fundamentals/gestures/tap?view=net-maui-7.0
<Image
Source="book_fspsydj.png"
Aspect="AspectFill"
WidthRequest="162" >
<Image.GestureRecognizers>
<TapGestureRecognizer Tapped="OnTapGestureRecognizerTapped"
Buttons="Primary,Secondary"
CommandParameter="{Binding Name}"
></TapGestureRecognizer>
</Image.GestureRecognizers>
</Image>
页面按钮点击事件
void OnTapGestureRecognizerTapped(object sender, TappedEventArgs args)
{
var bindingContext = ((Microsoft.Maui.Controls.BindableObject)sender).BindingContext;
var bindingObject = bindingContext as Monkey;
var baseParamModel = new BaseParamModel
{
Name = bindingObject.Name
};
var navigationParameter = new Dictionary<string, object>
{
{ "BasePM", baseParamModel }
};
if (args.Parameter?.ToString() == "refresh")
{
//DisplayAlert("温馨提示", "消息", "cancel", FlowDirection.RightToLeft);
DisplayAlert("温馨提示", "消息","关闭");
}
else if (sender is Image)
{
var routeKey = "ScriptureDetailPage";
Shell.Current.GoToAsync(routeKey, navigationParameter);
}
else if (sender is Label)
{
var routeKey = "MainPage";
Shell.Current.GoToAsync(routeKey, navigationParameter);
}
}
文档更新时间: 2023-04-03 10:38 作者:admin