My WPF application has a ListBox
whose ItemTemplate
looks like this:
<DataTemplate x:Key="DomainTemplate" DataType="DomainViewModel">
<Border BorderBrush="{Binding Converter={StaticResource BrushConverter}, Path=IsSelected}"
BorderThickness="3"
Grid.Column="0"
Name="SelectedBorder"
Padding="5">
<Button Click="SelectDomain_Click"
FontSize="16"
FontWeight="Bold"
IsEnabled="{Binding Path=CurrentSiteIsValid, RelativeSource={RelativeSource AncestorType={x:Type c:DomainPicker}}}"
MinHeight="60"
Tag="{Binding Path=DomainId}"
Width="120">
<TextBlock Text="{Binding Path=Name}"
TextAlignment="Center"
TextWrapping="WrapWithOverflow" />
</Button>
</Border>
</DataTemplate>
The window's width is driven by the width of the ListBox
. This is by design. There seems to a very large space between the vertical edges of the ListBox
and the items in it. Using Snoop, I see that the ListBoxItem
contains a Border
that is the same width as the ListBox
, has a Margin
of 0, and Padding
set to 2,0,0,0.
The Border
contains a ContentPresenter
whose width is 29 units smaller than the Border
that contains it. The Padding
on the Border
would seem to account for 2 of the units. Its Margin
is 0 and it has no padding property.
I actually would like to make this window a bit narrower if I can without making the Buttons
in the template any narrower. Where is that 29 unit space coming from? Is there any way to change its size?