Reputation: 3
I'm creating a simple UWP application for myself and stuck with lack of understanding of how binding and all that stuff works. Don't know how to explain it better So I created a simple example: https://gist.github.com/anonymous/744dc688d0663a3c14b7a2fc424316f8
The program has a list of selectable items on main screen. I can select several items, press a button and program will show new floating panel, with selected items (And I do further management of these items in my original program). I want this panel to be separate control because my MainPage is already overfilled with code.
The problem is. When I click on the button first time - it works as I expect. But then, when I change selected items and click button again, it shows panel with items from first selection.
My question is - how to do make it work? I have a feeling that it has to be something with INotifyPropertyChanged
but cannot understand it.
And I also would be glad to hear the overall recommendations. I'm not c# developer. I'm actually sys. admin but I know a little of python and I learned Delphi 7 in university. So I'm kind of learning c# in process of creation of this application.
UPD: If I change line 28 of SelectedItemsView.xaml
from
ItemsSource="{x:Bind SelectedItems}"
To
ItemsSource="{Binding SelectedItems, ElementName=SelectedItemsViewRoot}"
(and add x:Name="SelectedItemsViewRoot"
to user control attributes). It works as needed. So new question arrives - is this correct way to do this? I though that Binding
is kind of legacy and x:Bind
is newer approach that should be used in new apps.
Upvotes: 0
Views: 625
Reputation: 173
It's ok to use {Binding}
, but if you want to stick with {x:Bind}
, you can do this with OneWay mode (instead of default OneTime). For example: {x:Bind SelectedItems, Mode=OneWay}
.
I strongly encourage you to read these two official tutorials: Data binding overview and Data binding in depth.
In short, {Binding}
is not legacy. It's actually a bit more flexible, but it's performed in runtime, while {x:Bind}
is perfmormed at compile time, thus a bit more performant.
Upvotes: 1