开发者

Select whole item in ListBox in WPF [duplicate]

This question already has answers here: Stretch ListBox Items hit area to full width of the ListBox? ListBox style is set implicity through a theme (2 answers) Closed 6 years ago.

I've been googling around for something similar to FullRowSelect for a listview.开发者_如何转开发 Currently my listbox items are only selectable if you click on a part of it that is being taken up with content eg a textblock, item etc. This means that the "clickable" area is dependant on how long the entry is, but ideally i'd like to be able to click anywhere within the rectangle that defines each item.

I hope that makes sense


You need to adjust the ItemContainerStyle within the ListBox so that its HorizontalContentAlignment is set as Stretch versus Left. You can still align the content within the ListBoxItem as needed.

    <Window.Resources>
        <Style x:Key="Stretched" TargetType="{x:Type ListBoxItem}">
            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        </Style>
    </Window.Resources>

    <Grid>
        <ListBox ItemContainerStyle="{StaticResource Stretched}">
            <ListBox.Items>
                <ListBoxItem>
                    <Grid>
                        <TextBox HorizontalAlignment="Left" Height="25" Width="100"/>
                    </Grid>
                </ListBoxItem>
                <ListBoxItem>
                    <Grid>
                        <TextBox HorizontalAlignment="Left" Height="25" Width="100"/>
                    </Grid>
                </ListBoxItem>
            </ListBox.Items>
        </ListBox>
    </Grid>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜