Xamarin Listview:滚动时标签IsVisible绑定消失

时间:2019-10-03 15:54:41

标签: xamarin

我有一个列表视图,我想根据布尔isShop属性的值显示或隐藏Label。

第一次加载屏幕时,它可以正常工作,但是当我滚动列表视图时,标签会出现并消失。

请,请您帮我一下。谢谢!

这是ViewModel

private async Task LoadOrdersTimeSlot(OrdersByTimeSlotRequest request)
{
    IsBusy = true;

    UserDialogs.Instance.ShowLoading();

    try
    {
        var orders = await _timeSlotService.GetOrdersByTimeSlot(request);

        OrderResponse = orders;
    }
    catch (Exception ex)
    {
        UserDialogs.Instance.Alert($"{Resources.AppResources.RestServiceError} {ex.Message}");
        Crashes.TrackError(ex, new Dictionary<string, string>{
            { "Method", "LoadOrdersTimeSlot" }
        });
        if (OrderResponse == null)
            await NavigationService.NavigateBackAsync();
    }
    finally
    {
        try
        {

            if (OrderResponse != null)
            {
                foreach (var pedido in OrderResponse.pedidos)
                {
                    if (pedido.estadoEntrega == 5)
                    {
                        pedido.confirmado = true;
                    }
                    else
                    {
                        pedido.confirmado = false;
                    }

                    pedido.OnPropertyChanged("color");
                }
            }
        }
        catch (Exception ex)
        {
            UserDialogs.Instance.Alert($"{Resources.AppResources.RestServiceError} {ex.Message}");
            Crashes.TrackError(ex, new Dictionary<string, string>{
            { "Method", "LoadOrdersTimeSlot" }
        });
        }

        UserDialogs.Instance.HideLoading();
        IsBusy = false;
    }
}

这是模型

[NotMapped]
public bool isShop
{
  get
     {
        return (numeroPedido == 0);
     }
}

    public event PropertyChangedEventHandler PropertyChanged;

    public virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));

    }

这是视图

   <ListView x:Name="lvTimeOrders" 
    BackgroundColor="White"
    ItemsSource="{Binding OrderResponse.orders}"
    SelectedItem="{Binding SelectedOrder}"
    SeparatorVisibility="Default"
    <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell>
                <Grid Padding="10" BackgroundColor="White">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="AUTO"></RowDefinition>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"></ColumnDefinition>
                    </Grid.ColumnDefinitions>
                    <StackLayout Grid.Column="0" Orientation="Vertical" Margin="20,0,0,0">
                            <Label Text="{Binding orderName}"/>
                            <Label Text="{Binding orderNameAux"  IsVisible="{Binding isShop}" />
                        </StackLayout>
                    </StackLayout>
                </Grid>
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

1 个答案:

答案 0 :(得分:0)

我解决了将Xamarin.Forms从4.0.0.482894更新到4.2.0.848062的问题

感谢您的回答