-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ListBox selection not working correctly with CompileBinding #16144
Comments
It's a large repro to sort through, but it's related to interfaces in public ICollectionView<IPlaylistViewModel> Playlists { get; } = new CollectionView<IPlaylistViewModel>(); // Does not work
public CollectionView<IPlaylistViewModel> Playlists { get; } = new CollectionView<IPlaylistViewModel>(); // Works And the <ListBox ItemsSource="{Binding Playlists.Source}" SelectedItem="{Binding Playlists.CurrentItem}"> Edit: This is because |
Woah, simply adding a setter to that interface property makes the app work indeed! Very unintuitive solution to the problem. It is still a strange behavior that it breaks only for compiled binding and works with regular bindings. I just tested another bug I was having with compiled bindings with generic base class, that one seems to have been fixed. Compiled bindings overall working better than before, but should avoid those hard-to-pinpoint failures. |
Depends on the error message. If it says that setter is missing, then it all good and there is no issue. |
There are no errors, from what I can tell |
I've simplified the repro, However, it doesn't show the public partial class MainWindowViewModel : ViewModelBase
{
public ObservableCollection<int> Items { get; }
private int _selectedItem;
public int SelectedItem
{
get => _selectedItem;
set => SetProperty(ref _selectedItem, value); // Still compiles even when removed
}
public MainWindowViewModel()
{
Items = [1, 2, 3, 4, 5];
SelectedItem = Items.First();
}
} <Grid RowDefinitions="*,auto">
<ListBox ItemsSource="{Binding Items}" SelectedItem="{Binding SelectedItem}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<TextBlock Grid.Row="1" Text="{Binding SelectedItem}" />
</Grid> The issue is that there seems to be no logged sanity check for the I think this should be a compile-time failure and force the dev to specify |
@stevemonaco validation in compile time is problematic, because we can't get BindingMode during compilation, unless it's specified explicitly. |
Describe the bug
When CompileBinding is enabled, ListBox selections aren't working as expected, but work perfectly fine when disabled.
To Reproduce
BindingBug.zip
Here is a simple repro project.
On the left are Playlists, on the right are Folders. Click "+" above Playlists twice to add 2 items. Add a folder in each. Works fine.
Now, edit MainView and remove all
x:CompileBindings
references. Try again.This time, selecting a Playlist on the left doesn't change the displayed Folder on the right.
Expected behavior
It should behave like when CompileBinding is disabled.
Avalonia version
11.1.0-rc1
OS
Linux
Additional context
I believe I reported this a long while ago but didn't have time to investigate further and just disabled CompileBinding. Seeing it is still an issue in 11.1.0-rc1, I''m finally providing the simple repo.
Now it's causing me an issue because disabling CompileBinding is causing a problem with Trimming.
The text was updated successfully, but these errors were encountered: