寻找有关如何仅使用代码将事件挂钩到 Silverlight 的 DataTemplate 的信息。这会使我的浏览器在渲染时崩溃。
private DataTemplate Create(Type type)
{
DataTemplate dt = new DataTemplate();
string xaml = "<DataTemplate x:Name='dt' xmlns='http://schemas.microsoft.com/client/2007' xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' xmlns:basics='clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls' >"
+ "<Border Height='135' Width='110' HorizontalAlignment='Left' VerticalAlignment='Top' Background='#7FFCFAFA' CornerRadius='5,5,5,5'>"
+ "<StackPanel Orientation='Vertical' Width='110' Height='135'>"
+ "<Image Source='{Binding Path=ThumbnailPath}' Width='64' Height='64' Margin='5' HorizontalAlignment='Left' />"
+ "<TextBlock Text='{Binding Path=Title}' Margin='5' FontFamily='Verdana' HorizontalAlignment='Left' TextWrapping='Wrap' Foreground='#FFFAF8F8' Width='100' FontSize='9' />"
+ "<TextBlock Text='{Binding Path=FileDuration}' Margin='5' FontFamily='Verdana' HorizontalAlignment='Left' Foreground='#FFFAF8F8' Width='100' FontSize='9'/>"
+ "<StackPanel Orientation='Horizontal' Background='{x:Null}' x:Name='GridMenuBar'>"
+ "<Button ClickMode='Press' x:Name='play_buttons' HorizontalAlignment='Left' Template='{StaticResource GlassPlay}' BorderBrush='{x:Null}' Foreground='#FFF9F7F7' Background='{x:Null}' />"
//+ "<Button Height='Auto' HorizontalAlignment='Left' VerticalAlignment='Top' Width='Auto' Content='Button' x:Name='addPlayListItemButton' Template='{StaticResource GlassAddPlaylist}' Click='addPlayListItemButton_Click' />"
+ "</StackPanel>"
+ "</StackPanel>"
+ "</Border>"
+ "</DataTemplate>";
dt = (DataTemplate)XamlReader.Load(xaml);
return dt;
}