繁体   English   中英

将 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;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM