2011-05-27 36 views
0

我在ResourceDictionary中有DataTemplate。現在我在模板中有一個GroupBox,我想在其中使用MouseDown事件。但ResourceDictionary沒有代碼 (按預期),沒有鏈接到我使用字典中的東西的文件背後的代碼。ResourceDictionary中的事件

如何使用此事件?

+0

也許使用附加屬性/行爲? – 2011-12-08 18:46:23

回答

0

我不知道這是否適用於你,但我有一個類似的情況。 我想在我的ListBox的每個標籤上使用MouseDown事件。 所以這就是我做的:我將ListBox.ItemTemplate設置爲ContentPresenter。 然後我在該ContentPresenter上使用了MouseDown事件。我將ContentPresenter的ContentTemplate 設置爲我標籤的DataTemplate,它運行良好,從而將我的DataTemplate與MouseDown事件分開。

<ListBox 
    ItemsSource="{Binding}" 
    > 
    <ListBox.ItemTemplate> 
     <DataTemplate> 
      <ContentPresenter 
       ContentTemplate="{StaticResource myLabelTemplate}" 
       MouseDown="Event"> 
      </ContentPresenter> 
     </DataTemplate> 
    </ListBox.ItemTemplate> 
</ListBox> 

對不起我的英文不好;)