ListView Item not updateing correctly on UWP

Tom92Tom92 ✭✭USMember ✭✭
edited July 2017 in Xamarin.Forms

Hi,

Ive a ListView with ViewCell which contains a Label and a Button, my List is for showing Todo Items and the Button is to mark the Todo Item done and show the status on the Button as Text (with a Unicode Checkmark or Cross).
So I want to change the Button Text when a bool attribute binded to a DataTrigger raises PropertyChaged.

My Model Class "TodoItem" implements the IPropertyChanged interface and my "TodoItemViewModel" has a OberservableCollection with TodoItems and implements the IPropertyChanged interface too ( Iam using the NuGet package "PropertyChanged.Fody" to implement the interface).

For Android and iOS its working perfectly, when Iam clicking the Button of a ListView Item, the "done" Attribute of the TodoItem in the OberservableCollection gets changed to "true" and so the PropertyChaged Event gets triggert and causes the Button DataTrigger in XAML to correctly update the Text of the clicked Button.

But on UWP the Button Text sometimes seems to do not update correctly and gets Empty (normally it sould show a Checkmark or a Cross).

Here is my XAML snippet:

<ListView x:Name="listView" ItemsSource="{Binding TodoItems}" HasUnevenRows="true" Margin="5">            
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <StackLayout Orientation="Horizontal" BackgroundColor="LightGray">                            
                            <Label  Text="{Binding name}"  FontSize="Large" FontAttributes="Bold" HorizontalOptions="CenterAndExpand"/>

                            <Button Clicked="doneButton_Clicked" CommandParameter="{Binding .}" HorizontalOptions="End" >
                                <Button.Triggers>
                                    <DataTrigger  TargetType="Button" Binding="{Binding done}" Value="true">
                                        <Setter Property="Text" Value="&#x2714;"/>
                                    </DataTrigger>
                                    <DataTrigger TargetType="Button" Binding="{Binding done}" Value="false">
                                        <Setter Property="Text" Value="&#x2716;"/>
                                    </DataTrigger>
                                </Button.Triggers>
                            </Button>

                        </StackLayout>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
</ListView>

Here is the TodoItemViewModel which is binded as BindingContext in "OnAppearing" method in the CodeBehind of the XAML :

[AddINotifyPropertyChangedInterface]  //From NuGet PropertyChanged.Fody
    public class TodoItemViewModel
    {

        public ObservableCollection<TodoItem> TodoItems { get; set; } //Binded to ListView.ItemsSource

        public TodoItemModel()
        {
        }
    }

Here ist the method for Button Clicked:

private async void doneButton_Clicked(object sender, EventArgs e)
        {
            Button btn = sender as Button;
            TodoItem todoItem= btn.CommandParameter as TodoItem;

            if (todoItem != null && btn != null && btn.IsEnabled && btn.IsVisible)
            {
                if (!todoItem.done)
                {                   
                    todoItem.done = true;                    
                }
                else
                {                   
                    todoItem.done = false;                    
                }
                await database.Add(todoItem);
            }
        }

Here is a screenshot of the ListView on UWP (Problem marked with blue circle):

I hope someone can help me with this annoying problem on UWP...

Thanks!

Regards,

Tom

Posts

  • JohnHardmanJohnHardman mod GBUniversity mod
    edited July 2017

    @Tom92 - Have you checked Bugzilla? There have been a number of XF bugs that have caused issues like this, but in this case I wonder if you might be hitting this one - https://bugzilla.xamarin.com/show_bug.cgi?id=58049 (see the comment about plain Labels)

  • Tom92Tom92 ✭✭ USMember ✭✭

    @JohnHardman

    For testing now Iam changing the TodoItem.name to DateTime.Now in ListView ItemTapped method.

    The name isnt getting changed every time I click on the ListView Item, so I think Iam hitting your linked bug.

    So now I will follow the status of this bug on bugzilla.

    Thank you for your fast help!

  • NicholasBauerNicholasBauer ✭✭ USMember ✭✭
    edited August 2017

    I'm getting what I think is a similar problem. I'm trying to change the layout of a grid shown inside a ViewCell, which works by setting LayoutBounds in an AbsoluteLayout. Rarely, an item will generate with the new value, but most often not. I've checked everything, and the control works fine when it isn't inside a ViewCell. All PropertyChanged handlers are running and the layout bounds do seem to be updating, but the visual almost never reflects those changes.

Sign In or Register to comment.