Reputation: 1618
I have a list box with an ItemTemplate (shown below). When i point mouse cursor at the button or the text box that are in the item of list box, item is marked and when i point at the empty place in the item of listbox, then not. This depends on the length of the column grid. What needs to change that to the length item depends on the length of the listbox
<DataTemplate x:Key="MetroAdvensedListBoxItemTemplate">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="40"/>
<ColumnDefinition Width="200"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Margin="5">
<TextBlock Text="{Binding Path=Title, FallbackValue=Title}" FontFamily="Segoe UI Light" FontSize="20"
Foreground="{Binding RelativeSource={RelativeSource AncestorType=ListBoxItem, Mode=FindAncestor}, Path=Foreground}" />
</StackPanel>
<StackPanel Grid.Column="1" Margin="5">
<Path Data="{Binding Image}" Stretch="Uniform" Width="28" Height="28"
Fill="{Binding RelativeSource={RelativeSource AncestorType=ListBoxItem, Mode=FindAncestor}, Path=Foreground}" />
</StackPanel>
</Grid>
</DataTemplate>
Upvotes: 0
Views: 1237
Reputation: 50692
There are two things you need to do:
Only when a graphical item has a color it will receive mouse clicks (and other mouse events) so set the background color of the Grid in the DataTemplate
Stretch the items in a ListBox: Making a grid in a ListView ItemTemplate fill
Upvotes: 1
Reputation: 488
I am not understand, what does it mean "When i point mouse cursor at the button or the text box that are in the item of list box, item is marked and when i point at the empty place in the item of listbox, then not."
If you need your item's width match to width of ListBox, set ListBox.HorizontalContentAlignment="Stretch".
Upvotes: 0