I have a database beatbox with a DataTemplate setup. The DataTemplate contains a Grid control with two column widths Auto and *. I would like this column to always populate the ListBoxItem and never be projected behind the LisBox control to make the horizontal scrollbar visible.
I can bind MaxWidth to the DataTemplate grid using:
MaxWidth="{Binding RelativeSource={RelativeSource AncestorType={x:Type ListBox}}, Path=ActualWidth}"
Is this the best way to achieve this?
I also have an ItemContainerStyle setting for the following. Triggers have been removed to make code smaller and easier to read.
<Style x:Key="ListBoxItemContainer" TargetType="{x:Type ListBoxItem}">
<Setter Property="Padding" Value="3"/>
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Border x:Name="Border" BorderBrush="{x:Null}" CornerRadius="4" BorderThickness="1" Margin="1">
<Border x:Name="InnerBorder" BorderBrush="{x:Null}" CornerRadius="4" BorderThickness="1">
<ContentPresenter x:Name="ContentPresenter" Margin="{TemplateBinding Padding}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}"/>
</Border>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
source
share