c# - 在 Xamarin Forms 中添加新的“注释”时如何将 SwipeView 添加到 CollectionView
问题描述
我目前正在为一个学校项目制作一个笔记应用程序。我没有太多经验,请见谅。
当新项目添加到“笔记”列表中时,我想将 SwipeView 添加到我的 CollectionView 中,这将允许用户删除笔记。
我在 xamarin 中使用了默认的弹出布局来帮助我。
ItemsPage xaml
<?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="xamarinMobileTest.Views.ItemsPage"
Title="{Binding Title}"
xmlns:local="clr-namespace:xamarinMobileTest.ViewModels"
xmlns:model="clr-namespace:xamarinMobileTest.Models"
x:Name="BrowseItemsPage">
<ContentPage.ToolbarItems>
<ToolbarItem Text="Add Note" Command="{Binding AddItemCommand}" />
</ContentPage.ToolbarItems>
<RefreshView x:DataType="local:ItemsViewModel" Command="{Binding LoadItemsCommand}" IsRefreshing="{Binding IsBusy, Mode=TwoWay}">
<CollectionView x:Name="ItemsListView"
ItemsSource="{Binding Items}"
SelectionMode="None">
<CollectionView.ItemTemplate>
<DataTemplate>
<SwipeView>
<SwipeView.RightItems>
<SwipeItems Mode="Execute">
<SwipeItem Text="Delete"
BackgroundColor="Red"
Invoked="SwipeItem_Invoked"/>
</SwipeItems>
</SwipeView.RightItems>
<StackLayout Padding="5" x:DataType="model:Item">
<Label Text="{Binding Text}"
LineBreakMode="NoWrap"
Style="{DynamicResource ListItemTextStyle}"
FontSize="16"
FontAttributes="Bold"
TextColor="Black"/>
<Label Text="{Binding Description}"
LineBreakMode="NoWrap"
Style="{DynamicResource ListItemDetailTextStyle}"
FontSize="13"
TextColor="Black"/>
<StackLayout.GestureRecognizers>
<TapGestureRecognizer
NumberOfTapsRequired="1"
Command="{Binding Source={RelativeSource AncestorType={x:Type local:ItemsViewModel}}, Path=ItemTapped}"
CommandParameter="{Binding .}">
</TapGestureRecognizer>
</StackLayout.GestureRecognizers>
</StackLayout>
</SwipeView>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</RefreshView>
</ContentPage>
这是我到目前为止所拥有的,当尝试保存笔记时,应用程序崩溃了。任何帮助,将不胜感激。谢谢。
解决方案
您可能在指定时有错误command
在数据模板中
尝试像这样修复:
Command="{Binding Source={x:Reference BrowseItemsPage},Path=ItemTapped"
ItemTapped
是你的命令在你的viewmodel
.
推荐阅读
- objective-c - 如何在 MacOS 中保持沙盒模式获得批准的同时获取用户的 IP 地址?
- angular - 在包装器中显示 Angular Material mat-error
- c# - .NET Azure 函数 - 如何从流中返回 JSON 对象?
- c++ - Visual Studio 2015:外部“C”和“export”关键字
- python - 如何在预测中返回多个项目?
- excel - Excel 2016 Power Query 无法加载到电子表格
- scala - 可以将 udf 包装器添加到此数据帧操作
- ruby-on-rails - Spree API 身份验证扩展不起作用
- hive - 如何在 NiFi 中使用 UDF?
- tfs - 哪个是迭代 ID?