Hi,
I'm trying to make a standard WPF listbox be dynamically filled, and for each item in the list box to launch a command when clicked.
Currently I have a working listbox, which can be filled and each item will fire the correct command, but in order to fire the command I have to click the list item twice.
i.e, Click once to select the item, then click on the actual text to fire the command.
As the list is dynamically created, I had to create a data template for the list items:
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Margin="4,2,4,2">
<Hyperlink TextDecorations="None" Command="MyCommands:CommandsRegistry.OpenPanel">
<TextBlock Text="{Binding}" Margin="4,2,4,2"/>
</Hyperlink>
</TextBlock>
</DataTemplate>
</ListBox.ItemTemplate>
Basically, how do I remove the need to click twice? I have tried to use event triggers to fire the click event on the hyperlink element when the list box item is selected, but I can't get it to work.
Or, is there a better approach to dynamically fill a listbox and attach commands to each list item?
Thanks