ListBoxItem and Hyperlinks
I've got a few ListBoxItems that have an image and a textbox in them which highlights when clicked. What I'm having trouble figuring out is how to make whole listbox item doubleclick event fire to a hyperlink. Can someone assist me in this?
I've been looking at this but it seems that it is for the listbox as a whole rather than an item -- http://jarloo.com/code/wpf/wpf-listbox-doubleclick/.
Here is one of my listboxitems:
<ListBoxItem >
<Grid HorizontalAlignment="Stretch">
<Grid Margin="5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Border Grid.RowSpan="2"
BorderBrush="LightGray" BorderThickness="0"
Margin="0,0,5,0">
<Image Source="/IDE;component/Resources/Images/test1.ico" Height="64" Width="64" />
</Border>
<TextBlock Text="Google.com"
FontWeight="Bold"
Grid.Column="2"
Margin="0,0,0,5"/>
<TextBlock TextWrapping="Wrap" Text="To learn more information doubleclick this box to open the website."
Grid.Column="2" Grid.Row="2"/>
</Grid>
<Line X1="0" Y1="0" X2="0" Y开发者_如何学Go2="0" Stretch="Uniform"
Stroke="DarkGray"
VerticalAlignment="Bottom"/>
</Grid>
</ListBoxItem>
You seem to be specifying concrete items rather than having them generated from an ItemsSource, the link you named does not apply. I don't quite understand what you mean when you refer to a Hyperlink since i cannot see any in your code.
To handle a normal double click you could assign a handler in the ListBoxItem itself:
<ListBoxItem MouseDoubleClick="ListBoxItem_DoubleClick">
...
Is that what you want?
精彩评论