ListBoxItem produces “System.Windows.Data Error: 4” binding error

The easiest way to solve this is to ensure that your Listbox has a ItemContainerStyle. See the following example: <ListBox x:Name=”RecentItemsListBox” Grid.Row=”1″ BorderThickness=”0″ Margin=”2,0,0,0″ SelectionChanged=”RecentItemsListBox_SelectionChanged”> <ListBox.ItemContainerStyle> <Style TargetType=”{x:Type ListBoxItem}”> <Setter Property=”HorizontalContentAlignment” Value=”Left”/> <Setter Property=”VerticalContentAlignment” Value=”Center”/> </Style> </ListBox.ItemContainerStyle> … </ListBox> What happens is that your Items are being created, and by default they look for parent’s … Read more

How to capture a mouse click on an Item in a ListBox in WPF?

I believe that your MouseLeftButtonDown handler is not called because the ListBox uses this event internally to fire its SelectionChanged event (with the thought being that in the vast majority of cases, SelectionChanged is all you need). That said, you have a couple of options. First, you could subscribe to the PreviewLeftButtonDown event instead. Most … Read more

Double Click a ListBox item to open a browser

You can add a style to ListBox.ItemContainerStyle, and add an EventSetter there: <ListBox> …. <ListBox.ItemContainerStyle> <Style TargetType=”{x:Type ListBoxItem}” BasedOn=”{StaticResource {x:Type ListBoxItem}}”> <EventSetter Event=”MouseDoubleClick” Handler=”ListBoxItem_MouseDoubleClick”/> </Style> </ListBox.ItemContainerStyle> </ListBox> ListBoxItem_MouseDoubleClick is a method in your code behind with the correct signature for MouseDoubleClick.

WPF – How to combine DataTrigger and Trigger?

For anyone else who’s up against this problem, I found a solution that works for me. Of course, I’m still interested to see other interesting answers. Here’s what I did: <MultiDataTrigger> <MultiDataTrigger.Conditions> <Condition Binding=”{Binding RelativeSource={ RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem}}, Path=IsSelected}” Value=”True”/> <Condition Binding=”{Binding IsAvailable}” Value=”False”/> </MultiDataTrigger.Conditions> <Setter TargetName=”Name” Property=”Foreground” Value=”#F00″/> </MultiDataTrigger> There’s nothing special about … Read more