在MenuItem上使用DataTrigger在Xamarin.Forms中显示不同的状态
我试图在Xamarin.Forms中的ViewCell内的MenuItem上使用DataTrigger。ListView显示对话列表。如果对话被删除,我希望菜单项显示“还原”。如果对话没有被删除,我想显示“删除” 在生成时,我得到错误: 错误:位置12:49。无法解析单击的菜单项在MenuItem上使用DataTrigger在Xamarin.Forms中显示不同的状态,xamarin.forms,menuitem,datatrigger,xamarin.forms.listview,Xamarin.forms,Menuitem,Datatrigger,Xamarin.forms.listview,我试图在Xamarin.Forms中的ViewCell内的MenuItem上使用DataTrigger。ListView显示对话列表。如果对话被删除,我希望菜单项显示“还原”。如果对话没有被删除,我想显示“删除” 在生成时,我得到错误: 错误:位置12:49。无法解析单击的菜单项 您的问题在于这一行: 删除此行-MenuItem没有单击的属性单击是一个事件 您应该绑定到菜单项标记中单击的事件,例如: <?xml version="1.0" encoding="UTF-8"?> &
您的问题在于这一行:
删除此行-MenuItem没有单击的属性<代码>单击
是一个事件
您应该绑定到菜单项
标记中单击的事件,例如:
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="EventingVolunteers.MailboxBoxPage" Title="Mailbox - Box">
<ContentPage.Content>
<AbsoluteLayout x:Name="absLayout" VerticalOptions="FillAndExpand">
<ListView x:Name="listView" HasUnevenRows="true" ItemSelected="OnItemSelected" HeightRequest="{Binding Path=Height, Source={x:Reference absLayout}}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.ContextActions>
<MenuItem CommandParameter="{Binding Id}">
<DataTrigger TargetType="MenuItem" Binding="{Binding Is_Deleted}" Value="false">
<Setter Property="Clicked" Value="OnDelete" />
<Setter Property="Text" Value="Delete" />
<Setter Property="IsDestructive" Value="True" />
<Setter Property="Icon" Value="ic_delete.png" />
</DataTrigger>
<DataTrigger TargetType="MenuItem" Binding="{Binding Is_Deleted}" Value="true">
<Setter Property="Clicked" Value="OnRestore" />
<Setter Property="Text" Value="Restore" />
<Setter Property="IsDestructive" Value="False" />
<Setter Property="Icon" Value="" />
</DataTrigger>
</MenuItem>
</ViewCell.ContextActions>
<StackLayout Orientation="Horizontal" BackgroundColor="White" Padding="10,10,10,10">
<StackLayout Spacing="0" Orientation="Horizontal" HorizontalOptions="StartAndExpand">
<StackLayout Orientation="Vertical">
<StackLayout HorizontalOptions="StartAndExpand" Orientation="Horizontal">
<Label Text="{Binding Subject}" VerticalTextAlignment="Center" FontAttributes="Bold">
<Label.Triggers>
<DataTrigger TargetType="Label" Binding="{Binding Is_Unread}" Value="true">
<Setter Property="TextColor" Value="#337ab7" />
</DataTrigger>
</Label.Triggers>
</Label>
</StackLayout>
<StackLayout HorizontalOptions="StartAndExpand" Orientation="Horizontal">
<Label Text="{Binding Participant}" VerticalTextAlignment="Center" />
</StackLayout>
<StackLayout HorizontalOptions="StartAndExpand" Orientation="Horizontal">
<Label Text="{Binding Last_Message_At}" VerticalTextAlignment="Center" />
</StackLayout>
</StackLayout>
</StackLayout>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<ContentView x:Name="overlay" AbsoluteLayout.LayoutBounds="0, 0, 1, 1" AbsoluteLayout.LayoutFlags="All" IsVisible="True" BackgroundColor="#C0808080" Padding="10, 0">
<ActivityIndicator WidthRequest="110" HeightRequest="70" IsRunning="True" IsVisible="True" Color="Black" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand"/>
</ContentView>
</AbsoluteLayout>
</ContentPage.Content>
</ContentPage>