Menu.xaml
<MasterDetailPage.Master>
<ContentPage Title="Menu" Padding="0">
<ContentPage.Content>
<StackLayout>
<Grid BackgroundColor="LightGreen">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="10"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition Height="80"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="10"/>
</Grid.RowDefinitions>
<Label Grid.Column="1"
Grid.Row="2"
Text="DEC App"
TextColor="White"
FontSize="Large"/>
</Grid>
<syncfusion:SfTreeView x:Name="treeView">
<syncfusion:SfTreeView.Nodes>
<!--1st Menu-->
<treeviewengine:TreeViewNode Content="Menu 1">
<treeviewengine:TreeViewNode.ChildNodes>
<treeviewengine:TreeViewNode Content="Menu 1.1">
<!--SubMenu 1-->
</treeviewengine:TreeViewNode>
<treeviewengine:TreeViewNode Content="Menu 1.2">
<!--SubMenu 2-->
<treeviewengine:TreeViewNode.ChildNodes>
<treeviewengine:TreeViewNode Content="Menu 1.2.1"/>
<!--SubMenu 2.1-->
<treeviewengine:TreeViewNode Content="Menu 1.2.2"/>
<!--SubMenu 2.2-->
</treeviewengine:TreeViewNode.ChildNodes>
</treeviewengine:TreeViewNode>
</treeviewengine:TreeViewNode.ChildNodes>
</treeviewengine:TreeViewNode>
</syncfusion:SfTreeView.Nodes>
</syncfusion:SfTreeView>
</StackLayout>
</ContentPage.Content>
</ContentPage>
</MasterDetailPage.Master>
</MasterDetailPage>
Menu.xaml.cs
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace MasterDetailDemo
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class Menu : MasterDetailPage
{
public Menu()
{
InitializeComponent();
Detail = new NavigationPage(new MenuDetail());
}
我使用Syncfusion的SfTreeView在这里创建此菜单
但是我不知道如何在其上创建click事件,我尝试通读Syncfusion的所有文档,但并没有太大帮助。在此先感谢
您可以使用synca xamarin树视图的Tap命令。https://help.syncfusion.com/xamarin/treeview/mvvm#tap-command
以另一种方式,您还可以使用ItemTapped事件,https://help.syncfusion.com/cr/cref_files/xamarin/Syncfusion.SfTreeView.XForms~Syncfusion.XForms.TreeView.SfTreeView~ItemTapped_EV.html
我们想通知您,当在视图中单击树视图节点时,可以使用TreeView的ItemTapped事件或TapCommand来获取通知。我们随附了示例和代码段,供您在下面参考。
首先,将ItemTapped
事件添加到syncfusion:SfTreeView
: