【问题标题】:Events in ResourceDictionary [duplicate]ResourceDictionary 中的事件 [重复]
【发布时间】:2011-05-27 14:04:06
【问题描述】:
我在ResourceDictionary 中有一个DataTemplate。现在我在模板中有一个GroupBox,我想在其上使用MouseDown 事件。但是ResourceDictionary 后面没有代码
(按预期)并且没有链接到我使用字典中的内容的文件后面的代码。
如何使用此活动?
【问题讨论】:
标签:
wpf
xaml
code-behind
resourcedictionary
【解决方案1】:
我不知道这是否适用于您,但我有类似的情况。
我想在 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>
对不起我的英语不好;)