x:Bind default Mode is "OneTime" or sth else in Windows App SDK ?

Konstantinos Pavlis 0 Reputation points
2024-04-28T01:44:47.1666667+00:00

I have written the code below:

XAML code:

<ListView ItemsSource="{x:Bind players}">

***<ListView.ItemTemplate>***

    ***<DataTemplate x:DataType="local:Numbers">***


        

        ***<TextBlock Text="{x:Bind num}"/>***

    ***</DataTemplate>***

***</ListView.ItemTemplate>***
```***</ListView>***

C# code:

***public sealed partial class MainWindow : Window***

***{***

***ObservableCollection<Numbers> players = new ObservableCollection<Numbers>();***

***//More code here***

***}***

***class Numbers***

***{***

public Numbers(int x)

{

***this.num = x;***

}

internal int num;


When I run the program and add new "Numbers" instances in the above observable collection the ListView reflects these changes by adding the new instances. The question is how this is happening since the default Mode for x:Bind is OneTime and since the OneTime means that the ListView can't listen the Update Signals from the Observable Collection.

Windows development | Windows App SDK
Developer technologies | C#
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Castorix31 90,686 Reputation points
    2024-04-28T06:49:10.7233333+00:00

    See : https://learn.microsoft.com/en-us/windows/uwp/data-binding/data-binding-quickstart#binding-to-a-collection-of-items

    with :

    "ObservableCollection<T> class is a good collection choice for data binding, because it implements the INotifyPropertyChanged and INotifyCollectionChanged interfaces. These interfaces provide change notification to bindings when items are added or removed or a property of the list itself changes.

    "


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.