将 SwipeCardView SelectedItem 设置为 xamarin 形式的变量
Set SwipeCardView SelectedItem to a variable in xamarin form
我已经尝试为我的应用找到解决方案超过 3 天,但没有成功。
我需要在用户滑动或点击按钮时从 SwipeCardView 读取当前用户的电子邮件,并将其存储在一个变量中以备后用。有没有简单的解决方案可以达到这个目标?
看我的xaml:
<swipeCardView:SwipeCardView
x:Name="SwipeCardView"
ItemsSource="{Binding Candidates}" SwipedCommand="OnSwiped" SwipedCommandParameter="{Binding email}"
HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"
Padding="10"
SupportedSwipeDirections="Left,Right,Up">
<swipeCardView:SwipeCardView.ItemTemplate>
<DataTemplate>
<StackLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<Frame CornerRadius="10" Padding="8" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" >
<AbsoluteLayout>
<Image Source="{Binding profilePicture}" Aspect="AspectFill" AbsoluteLayout.LayoutBounds=".5, 0.5, 1, 1" AbsoluteLayout.LayoutFlags="All"></Image>
<Frame x:Name="fCandiate" CornerRadius="10" Padding="8" HeightRequest="50" AbsoluteLayout.LayoutBounds=".10, .98, 0.80, 0.20" AbsoluteLayout.LayoutFlags="All">
<StackLayout>
<Label Text="{Binding fullName}" TextColor="#4f4f4f" FontSize="Large" FontAttributes="Bold" />
<BoxView Color="#4f4f4f" HeightRequest="2" HorizontalOptions="Fill" />
<Label x:Name="candEmail" Text="{Binding email}" TextColor="#6f6f6f" FontSize="Medium" />
</StackLayout>
</Frame>
</AbsoluteLayout>
</Frame>
</StackLayout>
</DataTemplate>
</swipeCardView:SwipeCardView.ItemTemplate>
</swipeCardView:SwipeCardView>
还有我的xaml.cs
private void OnLikeClicked(object sender, EventArgs e)
{
string email = "???? (read from current item on SwipeCard)";
SwipeCardView.InvokeSwipe((MLToolkit.Forms.SwipeCardView.Core.SwipeCardDirection)MLToolkit.Forms.SwipeCardView.Core.SwipeCardDirection.Right);
DisplayAlert("Success", "You accepted the candidate. Page will be developed later" + email, "OK");
}
private void OnSwiped(object sender, SwipedCardEventArgs e)
{
switch (e.Direction)
{
case SwipeCardDirection.None:
break;
case SwipeCardDirection.Right:
DisplayAlert("Success", "You accepted the candidate. Page will be developed later" + e.Parameter.ToString(), "OK");
break;
case SwipeCardDirection.Left:
break;
case SwipeCardDirection.Up:
break;
case SwipeCardDirection.Down:
break;
}
}
我们将不胜感激。
在OnLikeClicked
var item = (MyClassName)SwipeCardView.TopItem;
var email = item.email;
或在OnSwiped
var item = (MyClassName)e.Item;
var email = item.email;
我已经尝试为我的应用找到解决方案超过 3 天,但没有成功。
我需要在用户滑动或点击按钮时从 SwipeCardView 读取当前用户的电子邮件,并将其存储在一个变量中以备后用。有没有简单的解决方案可以达到这个目标?
看我的xaml:
<swipeCardView:SwipeCardView
x:Name="SwipeCardView"
ItemsSource="{Binding Candidates}" SwipedCommand="OnSwiped" SwipedCommandParameter="{Binding email}"
HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"
Padding="10"
SupportedSwipeDirections="Left,Right,Up">
<swipeCardView:SwipeCardView.ItemTemplate>
<DataTemplate>
<StackLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<Frame CornerRadius="10" Padding="8" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" >
<AbsoluteLayout>
<Image Source="{Binding profilePicture}" Aspect="AspectFill" AbsoluteLayout.LayoutBounds=".5, 0.5, 1, 1" AbsoluteLayout.LayoutFlags="All"></Image>
<Frame x:Name="fCandiate" CornerRadius="10" Padding="8" HeightRequest="50" AbsoluteLayout.LayoutBounds=".10, .98, 0.80, 0.20" AbsoluteLayout.LayoutFlags="All">
<StackLayout>
<Label Text="{Binding fullName}" TextColor="#4f4f4f" FontSize="Large" FontAttributes="Bold" />
<BoxView Color="#4f4f4f" HeightRequest="2" HorizontalOptions="Fill" />
<Label x:Name="candEmail" Text="{Binding email}" TextColor="#6f6f6f" FontSize="Medium" />
</StackLayout>
</Frame>
</AbsoluteLayout>
</Frame>
</StackLayout>
</DataTemplate>
</swipeCardView:SwipeCardView.ItemTemplate>
</swipeCardView:SwipeCardView>
还有我的xaml.cs
private void OnLikeClicked(object sender, EventArgs e)
{
string email = "???? (read from current item on SwipeCard)";
SwipeCardView.InvokeSwipe((MLToolkit.Forms.SwipeCardView.Core.SwipeCardDirection)MLToolkit.Forms.SwipeCardView.Core.SwipeCardDirection.Right);
DisplayAlert("Success", "You accepted the candidate. Page will be developed later" + email, "OK");
}
private void OnSwiped(object sender, SwipedCardEventArgs e)
{
switch (e.Direction)
{
case SwipeCardDirection.None:
break;
case SwipeCardDirection.Right:
DisplayAlert("Success", "You accepted the candidate. Page will be developed later" + e.Parameter.ToString(), "OK");
break;
case SwipeCardDirection.Left:
break;
case SwipeCardDirection.Up:
break;
case SwipeCardDirection.Down:
break;
}
}
我们将不胜感激。
在OnLikeClicked
var item = (MyClassName)SwipeCardView.TopItem;
var email = item.email;
或在OnSwiped
var item = (MyClassName)e.Item;
var email = item.email;