删除列表中的所选项目

时间:2017-09-28 13:20:05

标签: listview xamarin xamarin.forms

我在Xaml中有如下所示的列表视图

<ListView x:Name="PreviousChatList" ItemsSource="{Binding PreviousMessagesList}" Grid.Row="0" ItemSelected="DeleteMessage">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell>
                            <StackLayout Orientation="Vertical">
                                <Label Text="{Binding }" FontSize="12" TextColor="Black"/>
                                <StackLayout IsVisible="{Binding ButtonsStackvisibility}" Orientation="Horizontal">
                                    <Button Text="Delete" TextColor="Brown" Clicked="DeleteClicked">></Button>
                                </StackLayout>
                            </StackLayout>
                        </ViewCell>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>

这里我想在选择列表中的项目时使ButtonsStackvisibility为真,

 private void DeleteMessage(object sender, Xamarin.Forms.SelectedItemChangedEventArgs e)
 {
     _chatWindowViewModel.ButtonsStackvisibility = true;
     ApplicationContext.seletedMessageToDelete = e.SelectedItem.ToString();
 }

点击DeleteClicked

 private void DeleteClicked(object sender, EventArgs e)
 {
    _chatWindowViewModel.MessagesList.Remove(ApplicationContext.seletedMessageToDelete);
 },

但我面临的问题是,该项目没有删除,可见性无效。如何解决?

0 个答案:

没有答案