我正在尝试构建一个WPF应用程序(使用C#.net),在其中我想在ListBox内添加按钮。
这是我放置在资源字典中的数据模板:
<DataTemplate x:Key="MYTemplate">
<StackPanel Margin="4">
<DockPanel>
<TextBlock Text="ISBN No:" DockPanel.Dock="Left" Margin="5,0,10,0" Foreground="AliceBlue" />
<TextBlock Text=" " />
<TextBlock Text="{Binding ISBN}" Foreground="LimeGreen" FontWeight="Bold" />
</DockPanel>
<DockPanel>
<TextBlock Text="Book Name:" DockPanel.Dock="Left" Margin="5,0,10,0" Foreground="AliceBlue"/>
<TextBlock Text=" " />
<TextBlock Text="{Binding BookName}" Foreground="LimeGreen" FontWeight="Bold" />
</DockPanel >
<DockPanel >
<TextBlock Text="Publisher Name:" DockPanel.Dock="Left" Margin="5,0,10,0" Foreground="AliceBlue" />
<TextBlock Text=" " />
<TextBlock Text="{Binding PublisherName}" Foreground="LimeGreen" FontWeight="Bold" />
</DockPanel>
<DockPanel>
<Button Name="MyButton" Content="Click Me">
</Button>
</DockPanel>
</StackPanel>
</DataTemplate>
如何在上述模板中为按钮标签添加点击事件?同时,我应该把将在按钮被点击时调用的方法放在哪里?