c# - 如何在滑动视图中获取属性的值
问题描述
所以我有一个Swipeview
,如果我向左滑动,我想得到狗的名字
<swipeCardView:SwipeCardView.ItemTemplate>
<DataTemplate>
<StackLayout HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand">
<Frame CornerRadius="10"
Padding="8"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand">
<AbsoluteLayout>
<AbsoluteLayout.GestureRecognizers>
<SwipeGestureRecognizer Direction="Left" Swiped="SwipeGestureRecognizer_Swiped" />
<SwipeGestureRecognizer Direction="Right" Swiped="SwipeGestureRecognizer_Swiped_1" />
<SwipeGestureRecognizer Direction="Up" Swiped="SwipeGestureRecognizer_Swiped_2" />
</AbsoluteLayout.GestureRecognizers>
<Image Source="{Binding dogImage}"
Aspect="AspectFill"
AbsoluteLayout.LayoutBounds=".5,0.5,1,1"
AbsoluteLayout.LayoutFlags="All" />
<Label FontSize="Large"
WidthRequest="30"
FontAttributes="Bold"
TextColor="White"
BackgroundColor="Black"
AbsoluteLayout.LayoutBounds="0.1,0.95,250,30"
AbsoluteLayout.LayoutFlags="PositionProportional">
<Label.FormattedText>
<FormattedString>
<Span Text="{Binding dogGender}" />
<Span Text=", " />
<Span Text="{Binding breed_Name}" />
</FormattedString>
</Label.FormattedText>
</Label>
</AbsoluteLayout>
</Frame>
</StackLayout>
</DataTemplate>
</swipeCardView:SwipeCardView.ItemTemplate>
我想获取Text="{Binding breed_Name}
在滑动视图中向左滑动并将其保存在变量中的值。
我怎么做?
解决方案
使用Command
而不是Swiped
事件并将其发送到CommandParameter
<swipeCardView:SwipeCardView.ItemTemplate>
<DataTemplate>
<StackLayout HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand">
<Frame CornerRadius="10"
Padding="8"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand">
<AbsoluteLayout>
<AbsoluteLayout.GestureRecognizers>
<SwipeGestureRecognizer Direction="Left"
Command="{Binding LeftCommand}"
CommandParameter={Binding breed_Name}"/>
...
<Label FontSize="Large"
WidthRequest="30"
FontAttributes="Bold"
TextColor="White"
BackgroundColor="Black"
AbsoluteLayout.LayoutBounds="0.1,0.95,250,30"
AbsoluteLayout.LayoutFlags="PositionProportional">
<Label.FormattedText>
<FormattedString>
<Span Text="{Binding dogGender}" />
<Span Text=", " />
<Span Text="{Binding breed_Name}" />
</FormattedString>
</Label.FormattedText>
</Label>
</AbsoluteLayout>
...
public Command LeftCommand => new Command<string>(LeftSwipe);
void LeftSwipe(string parameter)
{
var variable = parameter; //= breed_Name
}
推荐阅读
- javascript - 如何从 javascript 中的谷歌脚本 url 中获取返回值
- php - 当我尝试使用 PHP(8.0) 编写的注册系统时,我总是收到 SQLSTATE[42000] 1064 错误
- c++ - C++ 有时会输出垃圾值
- html - 在 Netsuite 中访问高级 pdf/html 中的 salesteam 子列表
- google-data-studio - Google Data Studio:按相对于今天的日期为行着色
- spring-boot - 带有 OpenAPI 3 和 Java 16 的 InaccessibleObjectException
- powershell - Powershell 监控文件夹并在有新文件时发送电子邮件
- javascript - 为什么重命名 HTML 文件会修复 Chrome 中的元素定位错误?
- android - 如何将drawable添加到撰写中的文本
- javascript - 禁用 FieldSet 时启用 html 按钮