Reputation: 341
I'm making a calendar as an exercise, and I get the Listbox Items to generate correctly. However, I don't want any spaces in between the borders. I have set HorizontalContentAlignment to stretch, and that didn't fix it.
<Grid>
<ListBox x:Name="monthCalendarListbox"
Grid.RowSpan="2"
BorderThickness="0"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Rows="5"
Columns="7"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<Border BorderBrush="Black"
BorderThickness="1">
<StackPanel Background="Transparent"
HorizontalAlignment="Stretch">
<Label Content="{Binding DayNumber}"/>
<Label Content="{Binding Message}"
VerticalAlignment="Center"
HorizontalAlignment="Center"/>
</StackPanel>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
EDIT:
It looks like ListBoxItem was getting a transparent border thrown in in addition to some padding (mentioned in the comments). So no more spacing but now I have double thick borders where the ListBoxItems meet. Any idea how to fix that?
<Grid>
<ListBox x:Name="monthCalendarListbox"
BorderThickness="0"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Style.Resources>
<SolidColorBrush x:Key="x:Static SystemColors.HighlightBrushKey" Color="Transparent"/>
<SolidColorBrush x:Key="x:Static SystemColors.ControlBrushKey" Color="Transparent"/>
<SolidColorBrush x:Key="x:Static SystemColors.HighlightTextBrushKey" Color="Black"/>
</Style.Resources>
<Setter Property="BorderBrush" Value="Black"/>
<Setter Property="BorderThickness" Value="1"/>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Rows="5"
Columns="7"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Background="Transparent">
<Label Content="{Binding DayNumber}"/>
<Label Content="{Binding Message}"
VerticalAlignment="Center"
HorizontalAlignment="Center"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
Upvotes: 0
Views: 143