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 App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
727 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,308 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Castorix31 81,831 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.

    "