Domanda

Is it possible to template a ListBoxItem so that in the visual tree the ContentPresenter is left out and I have direcctly the data template underneath the ListBoxItem?

È stato utile?

Soluzione

You may replace the ListBoxItem Style by one that does not have a ContentPresenter, like this very basic one:

<ListBox>
    <ListBox.ItemContainerStyle>
        <Style TargetType="ListBoxItem">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ListBoxItem">
                        <TextBlock Text="{Binding}"/>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </ListBox.ItemContainerStyle>
</ListBox>

For a more realistic Style you may copy the default ListBoxItem Style from here and replace the ContentPresenter by something that fits your needs.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top