Skip to content

ComboBox shows the selected item incorrectly #20572

@jyswjjgdwtdtj

Description

@jyswjjgdwtdtj

Describe the bug

Here is a combobox

        <ComboBox ItemsSource="{CompiledBinding ClassList}">
            <ComboBox.ItemTemplate>
                <DataTemplate DataType="controlDemo:MyControl">
                    <TextBlock Text="{CompiledBinding MyName}"></TextBlock>
                </DataTemplate>
            </ComboBox.ItemTemplate>
        </ComboBox>
public class ViewModel:ReactiveUI.ReactiveObject
{
    public AvaloniaList<MyControl> ClassList { get; } = new(){new MyControl(){MyName = "MyName One"},new MyControl(){MyName = "MyName Two"} };
}
public class MyControl:Control
{
    public string MyName
    {
        get;
        init;
    }
}

The combobox shows the ClassList. The MyControl s are shown correctly in popup, however, the selected one in SelectionBox turns out to be "Avalonia.Controls.Shape.Rectangle", although there's no "Avalonia.Controls.Shape.Rectangle" in all the code.

This issue may happen only when the model to be shown is a child class of Control.

Image Image

To Reproduce

As i have written in Describe the Bug

Expected behavior

Show the content according to the DataTemplate, not "Avalonia.Controls.Shape.Rectangle"

Avalonia version

The latest version(11.3.11)

OS

Windows

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions