unoplatform / uno.toolkit.ui

A set of custom controls for the WinUI and the Uno Platform not offered out of the box by WinUI, such as Card, TabBar, NavigationBar, etc.
https://platform.uno/
MIT License
84 stars 27 forks source link

[Windows][TabBar] SelectedIndex doesn't update selected item visual state #562

Open Soap-141 opened 1 year ago

Soap-141 commented 1 year ago

Current behavior

On Windows, we need to set SelectedIndex as a TwoWay binding if we want the selected item visual state to update.

Animation_90

Expected behavior

On Windows, we should not need to set SelectedIndex as a TwoWay binding if we want the selected item visual state to update.

Please note that I know that if we don't set SelectedIndex as a TwoWay binding the selected index property won't be updated since it's an expected behavior.

Animation_91

How to reproduce it (as minimally and precisely as possible)

  1. Download TabBarSample.zip
  2. Start on UWP (Would also be able to reproduce on WinUI)
  3. Click on the buttons
  4. Notice that the selected index is not updating the item visual state.

Nuget Package: Uno.Toolkit.UI

Package Version(s): 2.6.0-dev.40

Affected platform(s):

IDE:

Relevant plugins:

Anything else we need to know?

Youssef1313 commented 1 year ago

I took a look at this. Something very weird is going on on UWP.

First, the PropertyChanged event is subscribed twice (one for the TextBlock.Text binding, the other for TabBar.SelectedIndex binding)

Then, out of sudden, UWP decides to unsubscribe the event for TabBar.SelectedIndex.

image

I don't see why UWP should unsubscribe when TabBar.SelectedIndex setter is called.

@Xiaoy312 Do you have any idea?

Youssef1313 commented 1 year ago

Note to save time if someone will look: The project crashed for me with unrelated error, and solved by removing <XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" /> in App.xaml.

Youssef1313 commented 1 year ago

Oh it quite makes sense now. When the property is set explicitly, all OneWay bindings are cleared.

kazo0 commented 1 year ago

@Youssef1313, so this is a bug in TabBar then right? Not a binding thing in the sample?

Youssef1313 commented 1 year ago

@kazo0 The sample looks fine to me. I think yes it's a TabBar bug.

It affects Windows but not Uno targets because Uno doesn't remove the binding (which looks like another bug in Uno)

Guidemarcus commented 1 year ago

@Youssef1313 @Xiaoy312 quick question, I tried Uno.Toolkit.UI 3.0.5 and 3.1.0-dev.33 on the sample provided and the behavior is the same as described. Am I testing the right versions? Was the fix merge into Uno.Toolkit.UI 4.0.0-dev?

Lee31416 commented 7 months ago

Got the same issue yesterday with uno 4.10.13