0

I was wondering if there is a way to change the selection mode of a list view from single to multiple and vice versa from the press of a button. I have tried binding to the ListView selection mode but this is not working. Maybe I am doing something wrong.

<ListView SelectionMode="{x:Bind SelectionMode}"/>

In my on click button code:

if (MultipleSelectionModeEnabled)
{
     SelectionMode = ListViewSelectionMode.Multiple;
}
else 
{
     SelectionMode = ListViewSelectionMode.Single;
}
renners
  • 45
  • 6

2 Answers2

4

If you do everything right (cannot tell because I don't see the whole code), then adding Mode=OneWay to the x:Bind expression should help, because the default mode of x:Bind is OneTime.

<ListView SelectionMode="{x:Bind SelectionMode, Mode=OneWay}"/>
Marian Dolinský
  • 3,312
  • 3
  • 15
  • 29
2

x:Bind is a compile time binding. i.e, All compilation is completed before rendering. So if you want to force your changes, you need to call Bindings.Update()after the property is updated.

Take a look at the explanation about this on the Accepted Answer Here.

So Change your code like this

if (MultipleSelectionModeEnabled)
{
     SelectionMode = ListViewSelectionMode.Multiple;
}
else 
{
     SelectionMode = ListViewSelectionMode.Single;
}
Bindings.Update();

Good Luck.

Community
  • 1
  • 1
AVK
  • 3,893
  • 1
  • 22
  • 31