Skip to content
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

Binding on a UserControl inside a DataTemplate broken in 11.2.0 #17474

Closed
Asttear opened this issue Nov 11, 2024 · 0 comments · Fixed by #17683
Closed

Binding on a UserControl inside a DataTemplate broken in 11.2.0 #17474

Asttear opened this issue Nov 11, 2024 · 0 comments · Fixed by #17683

Comments

@Asttear
Copy link

Asttear commented Nov 11, 2024

Describe the bug

DataContext={Binding} on a UserControl inside a DataTemplate is broken in 11.2.0

11.2.0
image

11.1.4
image

To Reproduce

MainWindow.axaml

...
    <ContentControl Content="{Binding Book}">
        <ContentControl.DataTemplates>
            <DataTemplate DataType="m:Book">
                <StackPanel>
                    <TextBlock Background="Red" Text="{Binding}" />

                    <!-- <v:UserControl1 Background="Yellow" /> will be OK -->
                    <!--  however the following will be invisible  -->
                    <v:UserControl1 Background="Yellow" DataContext="{Binding}" />

                    <ContentControl Background="Green" Content="{Binding}">
                        <ContentControl.DataTemplates>
                            <DataTemplate x:DataType="m:Book">
                                <StackPanel>
                                    <TextBlock Text="{Binding}" />
                                </StackPanel>
                            </DataTemplate>
                        </ContentControl.DataTemplates>
                    </ContentControl>
                </StackPanel>
            </DataTemplate>
        </ContentControl.DataTemplates>
    </ContentControl>
...

UserControl1.axaml

...
    <ContentControl Content="{Binding}">
        <ContentControl.DataTemplates>
            <DataTemplate x:DataType="m:Book">
                <StackPanel>
                    <TextBlock Text="{Binding}" />
                </StackPanel>
            </DataTemplate>
        </ContentControl.DataTemplates>
    </ContentControl>
...

MainWindowViewModel.cs

public partial class MainWindowViewModel : ViewModelBase
{
    public Book Book { get; } = new();
}

Book.cs

public record Book(string Name = "Avalonia", int Price = 4000);

Expected behavior

Binding works properly as in 11.1.4

Avalonia version

11.2.0

OS

Windows

Additional context

May be related to #16242

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants