AvaloniaUI / Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
https://avaloniaui.net
MIT License
25.88k stars 2.24k forks source link

When mounted, TabStrip changes SelectedItem to the first one and then reverts it back #15891

Open optsing opened 5 months ago

optsing commented 5 months ago

Describe the bug

When mounted, TabStrip changes SelectedItem to the first one and then reverts it back.

To Reproduce

Add TabStrip to View, add TabItems and CurrentItem to ViewModel, watch CurrentItem changes.

public partial class MainViewModel : ViewModelBase
{
    public List<string> TabItems { get; } = ["Tab1", "Tab2", "Tab3"];

    [ObservableProperty]
    public string currentItem = "Tab2";

    partial void OnCurrentItemChanged(string value)
    {
        Debug.WriteLine(value);
    }
}

Just run the application and look at the logs:

Tab1
Tab2

Expected behavior

TabStrip should not change SelectedItem when mounted, like ListBox does not change it.

Avalonia version

11.0.10

OS

Windows

Additional context

No response

optsing commented 5 months ago

Apparently, the problem is with AlwaysSelected in SelectingItemsControl.cs and is relevant for 11.1.0-rc1