Silverlight 3 Datatemplate:触发button_click事件
我有一个存储在 ResourceDictionary 中的列表框的数据模板。该模板包含一个按钮,单击该按钮时应将列表框项目传递到单独的列表框,
<DataTemplate x:Key="ListBoxContentPresenterTemplate">
<StackPanel Orientation="Horizontal">
<StackPanel Height="75" Width="100">
<TextBlock x:Name="Surname" Text="{Binding Property1}" FontFamily="Arial" FontSize="16" FontWeight="Bold" d:LayoutOverrides="Width"/>
<TextBlock x:Name="Firstname" Text="{Binding Property2}" Foreground="#FFC9C23E" FontFamily="Arial" FontSize="12" d:LayoutOverrides="Width"/>
</StackPanel>
<Button x:Name="Button1" Content="Press" />
</StackPanel>
</DataTemplate>
我不知道如何触发该事件,因为将其添加到 xaml 中通常不会在这里工作(大概是因为它是一个模板)。 任何帮助将不胜感激。
I have a datatemplate for a listbox stored in the ResourceDictionary. The template contains a button which when clicked should pass the listbox item to a seperate listbox
<DataTemplate x:Key="ListBoxContentPresenterTemplate">
<StackPanel Orientation="Horizontal">
<StackPanel Height="75" Width="100">
<TextBlock x:Name="Surname" Text="{Binding Property1}" FontFamily="Arial" FontSize="16" FontWeight="Bold" d:LayoutOverrides="Width"/>
<TextBlock x:Name="Firstname" Text="{Binding Property2}" Foreground="#FFC9C23E" FontFamily="Arial" FontSize="12" d:LayoutOverrides="Width"/>
</StackPanel>
<Button x:Name="Button1" Content="Press" />
</StackPanel>
</DataTemplate>
I don't know how to fire the event as adding it in the xaml as I normally would doesn't work here(presumably as it's a template).
Any help would be much appreicated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
DataTemplate
不是订阅事件的问题。可能仅当您的DataTemplate
位于单独的资源文件中时,因此您没有合理的位置来放置事件处理程序。如果是这样,您可以使用命令 (我相信这也适用于版本 3)。DataTemplate
is not the problem to subscribe to events. May be only if yourDataTemplate
is located in a separate resources file, so you have no rational place to place the event handler. If so you can make use of Commands (I believe this will work in version 3 too).