简体   繁体   English

如何在xamarin.forms中单击操作栏图标?

[英]How to take click on action bar icon in xamarin.forms?

I added the Notification icon on action bar. 我在操作栏上添加了通知图标。 I want to take clicked on it. 我想点击一下。 So how can i do this? 那我该怎么办呢? Anyone knows please revert back with answer. 任何人都知道,请回复答案。

If you added a toolbar item you can do it like this: 如果添加了工具栏项,则可以这样进行:

ToolbarItems.Add(new ToolbarItem("Action Name", "Icon.png", async () =>
{
    //Your code on clicked
}));

To do it in Xaml, you need to add the command attribute: 要在Xaml中执行此操作,您需要添加命令属性:

<ContentPage.ToolbarItems>
    <ToolbarItem Name="Invite" Command="{Binding ToolbarItemCommand}"></ToolbarItem>
</ContentPage.ToolbarItems>

Then in your code behind define an ICommand named ToolbarItemCommand which will be triggered when the icon is clicked 然后在后面的代码中定义一个名为ToolbarItemCommand的ICommand,该ICommand将在单击图标时触发

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM