2014-04-26 34 views
-1

我想在列表框WPF - 我想在ListBox中的鼠標事件觸發的項目,但它的工作只是第一個子項

鼠標事件觸發的項目,但它的工作只是第一個子項。

<ListBox Name="myListBox" ItemsSource="{Binding }" 
      ScrollViewer.CanContentScroll="False" 
      ScrollViewer.VerticalScrollBarVisibility="Visible" 
      ScrollViewer.HorizontalScrollBarVisibility="Disabled"> 
     <ListBox.ItemTemplate> 
      <DataTemplate> 
       <Grid ClipToBounds="True"> 
        <Image Width="300" Grid.Column="0" Source="{Binding Path=Path}" 
          MouseMove="my_mouseMove" 
          MouseLeave="my_mouseLeave"/> 
        <Canvas> 
         <Rectangle x:Name="Helper" Width="500" Height="1" Fill="#FFD87A1D"/> 
        </Canvas> 
       </Grid> 
      </DataTemplate> 
     </ListBox.ItemTemplate> 
    </ListBox> 
  1. 我與圖像的事件。

  2. 它的工作原理的MouseMove,鼠標離開活動的第一個項目(圖)

    • 這些事件是在listItems中的範圍內移動Rectagle。
  3. 我想知道如何將(?)這個事件傳播給其他項目。

+0

請澄清,因爲它是不清楚。 – Aybe

+0

@ user3193287在我看來,您將'Canvas'放置在圖像頂部的'Rectangle'上。如果是這種情況,它會覆蓋你的圖像,'MouseMove'和'MouseLeave'不會被觸發。 – dkozl

回答

0

使用foreach循環後面的代碼是這樣的:

foreach(YourClassName item in mylistbox.Items) 
{ 

     //Make mousemove and mouseleave events here for item 
     //this approach will implement event triggers for every item in the listbox 
} 

或在XAML中做到這一點:

<Canvas> 
    <Rectangle x:Name="Helper" Width="500" Height="1" Fill="#FFD87A1D" MouseMove="my_mouseMove" MouseLeave="my_mouseLeave"/> 
    </Canvas> 

希望這有助於:)

+0

它沒有爲這兩種方式準備工作.. – Daniel

+0

試圖把帆布放在圖像後面.. – TheGaMeR123

相關問題