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

ComboBox will not show dropdown while in a TextBox InnerLeftContent #17644

Open
sunwayking opened this issue Nov 29, 2024 · 3 comments
Open

ComboBox will not show dropdown while in a TextBox InnerLeftContent #17644

sunwayking opened this issue Nov 29, 2024 · 3 comments
Labels

Comments

@sunwayking
Copy link

Describe the bug

I put a ComboBox inside TextBox.InnerLeftContent. The ComboBox dropdown didn't show itself when I click on the ComboBox.

To Reproduce

<TextBox VerticalContentAlignment="Center" Watermark="http://" IsHitTestVisible="True">
    <TextBox.InnerLeftContent>
        <ComboBox Margin="4" Width="100" AutoScrollToSelectedItem="True"  IsHitTestVisible="True"
                  ItemsSource="{Binding ProtocolPrefixes}"
                  SelectedIndex="{Binding SelectedProtocolPrefixIndex}">
            <ComboBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel Orientation="Horizontal"/>
                </ItemsPanelTemplate>
            </ComboBox.ItemsPanel>
            <ComboBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding}" />
                </DataTemplate>
            </ComboBox.ItemTemplate>
        </ComboBox>
    </TextBox.InnerLeftContent>
    <TextBox.InnerRightContent>
        <StackPanel Orientation="Horizontal" Spacing="4" Margin="4">
            <Button Content="POST" />
            <Button Content="GET" />
        </StackPanel>
    </TextBox.InnerRightContent>
</TextBox>```

### Expected behavior

The ComboBox that is inside TextBox.InnerLeftContent should show its dropdown content, when clicking on it.

### Avalonia version

11.2.2

### OS

_No response_

### Additional context

_No response_
@sunwayking sunwayking added the bug label Nov 29, 2024
@stevemonaco
Copy link
Contributor

stevemonaco commented Dec 4, 2024

The ComboBox doesn't receive OnPointerReleased which is where IsDropDownOpen is changed to display the dropdown. This is because TextBox.OnPointerPressed captures the mouse. This TextBox event happens because ComboBox.OnPointerPressed doesn't handle the event, even when it's determined that the :pressed pseudoclass is to be set.

else
{
PseudoClasses.Set(pcPressed, true);
}

I don't know of a reasonable workaround until the bug is fixed.

Repro without bindings:

combobox

<StackPanel>
    <TextBox
        VerticalContentAlignment="Center"
        IsHitTestVisible="True"
        Watermark="http://">
        <TextBox.InnerLeftContent>
            <ComboBox
                Width="100"
                Margin="4"
                AutoScrollToSelectedItem="True"
                IsHitTestVisible="True">
                <TextBlock Text="https" />
                <TextBlock Text="http" />
                <TextBlock Text="ftp" />
            </ComboBox>
        </TextBox.InnerLeftContent>
        <TextBox.InnerRightContent>
            <StackPanel
                Margin="4"
                Orientation="Horizontal"
                Spacing="4">
                <Button Content="POST" />
                <Button Content="GET" />
            </StackPanel>
        </TextBox.InnerRightContent>
    </TextBox>

    <ComboBox
        Width="100"
        Margin="4"
        AutoScrollToSelectedItem="True"
        IsHitTestVisible="True">
        <TextBlock Text="https" />
        <TextBlock Text="http" />
        <TextBlock Text="ftp" />
    </ComboBox>
</StackPanel>

@sunwayking
Copy link
Author

@stevemonaco Thanks for helping me to figure out why inner combobox not showing its dropdown.
However a workaround is still needed.

@stevemonaco
Copy link
Contributor

There's a pretty hacky workaround with event subscriptions. Building from the example above, naming the TextBox, and going into code-behind:

public MainWindow()
{
    InitializeComponent();

    var left = textbox.InnerLeftContent as Control;
    left?.AddHandler(PointerPressedEvent, InnerLeftContent_PointerPressed, RoutingStrategies.Bubble);
}

private void InnerLeftContent_PointerPressed(object? sender, PointerPressedEventArgs e)
{
    e.Handled = true;
}

Handling the event here will not allow the TextBox to capture the mouse when clicked on the InnerLeftContent area (assuming hit test succeeds, of course). A proper fix would require a change to the Avalonia code base.

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

No branches or pull requests

2 participants