我有一个列表,其中有歌曲作为项目。长按元素会显示一个上下文菜单。
<DataTemplate x:Key="SongTemplate">
<ViewCell>
<ViewCell.ContextActions>
<MenuItem Text="Edit" />
<MenuItem Text="Delete"/>
</ViewCell.ContextActions>
<StackLayout Padding="15,5" VerticalOptions="Center">
<Label Text="{Binding Title}"
FontSize="16"/>
<Label Text="{Binding Performer}"
FontSize="12"/>
</StackLayout>
</ViewCell>
</DataTemplate>
这很好用,但是我现在需要绑定,以便根据bool IsAdmin(位于AllSongsViewModel中)打开上下文菜单。>
public bool IsAdmin => _authService.LoggedUser.Role == "Admin";
但是我不知道如何将此属性绑定到上下文菜单
我有一个列表,其中有歌曲作为项目。长按该元素应显示一个上下文菜单。 AllSongsViewModel.xaml:
XAML:
<DataTemplate x:Key="SongTemplate">
<ViewCell BindingContextChanged="OnBindingContextChanged">
<StackLayout Padding="15,5" VerticalOptions="Center">
<Label Text="{Binding Title}"
FontSize="16"/>
<Label Text="{Binding Performer}"
FontSize="12"/>
</StackLayout>
</ViewCell>