Keeping a ListBox in a Grid white

Here you have a very simple standalone XAML file:

<!-- MyListBox.xaml -->
<Page 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainPage" Height="100" Width="525">
    <ListBox>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="42"></RowDefinition><!-- THE MAGIC LINE-->
            </Grid.RowDefinitions>
        </Grid>
    </ListBox>
</Page>

If you open this in Internet Explorer and click the ListBox, then it turns blue. However, if you remove Height="42" from THE MAGIC LINE then the box remains white when you click it. I have two questions:

  1. Why does the presence or absence of Height="42" make a difference?
  2. I would like to make the box permanently white even when THE MAGIC LINE contains an explict declaration of height. How do you do this?

Answers


blue color is the default selection color for your listbox. the easiest way to get around is to set the following

    <ListBox>
        <ListBox.Resources>
            <Style TargetType="{x:Type ListBox}">
                <Style.Resources>
                    <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent"/>
                </Style.Resources>
            </Style>
        </ListBox.Resources>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="42"></RowDefinition>
                <!-- THE MAGIC LINE-->
            </Grid.RowDefinitions>
        </Grid>
    </ListBox>

EDIT: your title is something different to the rest of your question. leave a comment if you want something different


Need Your Help

Date conversation error during jaxb marshall on a JPA object using eclipselink

jpa jaxb eclipselink

I stuck on this Date conversation error for quite some time ...

Cell Locking on Save if data has been entered

excel-vba locking vba excel

This is a follow up from this question, Lock Cells after Data Entry. I have progressed from asking that question but encountered more problems so felt I should ask a new question. The workbook is e...