2011-04-13 102 views
1

我有幾個ListBoxItems有一個圖像和一個文本框在他們點擊時突出顯示。我遇到的困難是如何使整個列表框項目doubleclick事件觸發到超鏈接。有人可以幫助我嗎?ListBoxItem和超鏈接

我一直在看這個,但它似乎是列表框作爲一個整體,而不是一個項目 - http://jarloo.com/code/wpf/wpf-listbox-doubleclick/

這裏是我的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" Y2="0" Stretch="Uniform" 
     Stroke="DarkGray" 
     VerticalAlignment="Bottom"/> 
    </Grid> 
</ListBoxItem> 

回答

1

你似乎明確了具體的項目,而不是從一個的ItemsSource已經產生他們,你指定的鏈接不適用。我不太明白你提到超鏈接時的意思,因爲我在代碼中看不到任何內容。

以處理ListBoxItem中本身就是一個正常的雙擊,你可以指定一個處理程序:

<ListBoxItem MouseDoubleClick="ListBoxItem_DoubleClick"> 
    ... 

這是你想要的嗎?

+0

啊!感謝這一點。我一直試圖,但它不會允許它。乾杯 – 2011-04-13 21:34:12