使用Xaml中的以下代码,我得到一个空引用异常
<toolkit:DataGrid x:Name="Roosters" Grid.Row="6" Grid.ColumnSpan="4" Grid.Column="0" ItemsSource="{Binding Premies}" IsReadOnly="True" CanUserAddRows="False" CanUserDeleteRows="False" SelectionMode="Single" VirtualizingStackPanel.VirtualizationMode="Recycling" MaxWidth="2560" MaxHeight="1600">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseDoubleClick">
<command:EventToCommand Command="{Binding PremieRoostersSelectionChanged}" CommandParameter="{Binding SelectedItem, ElementName=Roosters}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</toolkit:DataGrid>
堆栈跟踪:
at System.Windows.Markup.ReflectionHelper.IsPublicType(Type type)
at System.Windows.Markup.XamlTypeMapper.UpdateAttachedPropertyMethdodInfo(BamlAttributeInfoRecord attributeInfo, Boolean isSetter)
at System.Windows.Markup.XamlTypeMapper.UpdateAttachedPropertyGetter(BamlAttributeInfoRecord attributeInfo)
at System.Windows.Markup.PropertyDefinition.get_AttachedPropertyGetter()
at System.Windows.Markup.BamlCollectionHolder.InitDefaultValue()
at System.Windows.Markup.BamlCollectionHolder..ctor(BamlRecordReader reader, Object parent, Int16 attributeId, Boolean needDefault)
at System.Windows.Markup.BamlRecordReader.ReadPropertyIListStartRecord(BamlPropertyIListStartRecord bamlPropertyIListStartRecord)
at System.Windows.Markup.BamlRecordReader.ReadRecord(BamlRecord bamlRecord)
at System.Windows.Markup.BamlRecordReader.Read(Boolean singleRecord)
at System.Windows.Markup.TreeBuilderBamlTranslator.ParseFragment()
at System.Windows.Markup.TreeBuilder.Parse()
at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
at PremiesWpf.Views.PremieRoosters.InitializeComponent()
我确定问题存在,因为当我删除Triggers部分时一切正常。如果我只删除EventToCommand部分,则仍会发生错误。
这个项目是在框架3.5中构建的(它的遗产,并且由于影响巨大而无法升级)。
这也是一个WPF表单,它在winforms中托管以使事情变得更糟。
有问题的事件:
public DelegateCommand<Premie> PremieRoostersSelectionChanged { get; set; }
PremieRoostersSelectionChanged = new DelegateCommand<Premie>(premie =>
{
Current = premie;
});