© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
3 replies
Nacho Man Randy Cabbage

Textblock is overlapping with combobox items (WPF)

I am trying to make it so the combobox has some static text and will never show selected items. I thought I could have a TextBlock on top of it, but for some reason items from the combobox seem to randomly appear underneath it. I can't reproduce it every time.
Here's the relevant xaml:

<Grid
    Width="130"
    VerticalAlignment="Center">
    <Grid.Resources>
        <CollectionViewSource x:Key="Columns" Source="{Binding MySource}" />
        <DataTemplate DataType="{x:Type models:MyLabel}">
            <CheckBox
                Checked="CheckBox_CheckChanged"
                Content="{Binding Label}"
                IsChecked="{Binding IsSelected}"
                Unchecked="CheckBox_CheckChanged" />
        </DataTemplate>
    </Grid.Resources>
    <ComboBox
        IsEditable="False"
        IsReadOnly="True"
        SelectedIndex="-1">
        <ComboBox.ItemsSource>
            <CompositeCollection>
                <CheckBox
                    x:Name="SelectAllCb"
                    Checked="SelectAllCb_CheckedChanged"
                    Content="Select All"
                    Unchecked="SelectAllCb_CheckedChanged" />
                <CollectionContainer Collection="{Binding Source={StaticResource Columns}}" />
            </CompositeCollection>
        </ComboBox.ItemsSource>
    </ComboBox>
    <TextBlock
        Margin="5,0,0,0"
        VerticalAlignment="Center"
        IsHitTestVisible="False"
        Text="Show/Hide Columns" />
</Grid>
<Grid
    Width="130"
    VerticalAlignment="Center">
    <Grid.Resources>
        <CollectionViewSource x:Key="Columns" Source="{Binding MySource}" />
        <DataTemplate DataType="{x:Type models:MyLabel}">
            <CheckBox
                Checked="CheckBox_CheckChanged"
                Content="{Binding Label}"
                IsChecked="{Binding IsSelected}"
                Unchecked="CheckBox_CheckChanged" />
        </DataTemplate>
    </Grid.Resources>
    <ComboBox
        IsEditable="False"
        IsReadOnly="True"
        SelectedIndex="-1">
        <ComboBox.ItemsSource>
            <CompositeCollection>
                <CheckBox
                    x:Name="SelectAllCb"
                    Checked="SelectAllCb_CheckedChanged"
                    Content="Select All"
                    Unchecked="SelectAllCb_CheckedChanged" />
                <CollectionContainer Collection="{Binding Source={StaticResource Columns}}" />
            </CompositeCollection>
        </ComboBox.ItemsSource>
    </ComboBox>
    <TextBlock
        Margin="5,0,0,0"
        VerticalAlignment="Center"
        IsHitTestVisible="False"
        Text="Show/Hide Columns" />
</Grid>

Here's what it looks like sometimes:
image.png
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ [WPF] How to input ComboBox into TextBlock
C#CC# / help
3y ago
Wpf combobox
C#CC# / help
2y ago
Wpf combobox problem
C#CC# / help
2y ago
❔ Binding WPF Combobox
C#CC# / help
3y ago