如果我添加一个事件处理程序到组合框,SelectionChanged for examle,即时获取异常。有人可以告诉我为什么。为什么我在ComboBox中得到异常('System.NullReferenceException')
奇怪的行为,因为在我的笔记本电脑上安装了VS7与VS2010它运行成功。
异常:
A first chance exception of type 'System.NullReferenceException' occurred in wpfapplication.exe
Additional information: Object reference not set to an instance of an object.
异常调用堆栈:
PresentationFramework.dll System.Windows.FrameworkTemplate.LoadTemplateXaml(System.Xaml.XamlReader templateReader,System.Xaml.XamlObjectWriter currentWriter)+ 0x247 bytes
PresentationFramework.dll!System.Windows.FrameworkTemplate.LoadTemplateXaml(System.Xaml.XamlObjectWriter objectWriter)+ 0x66 bytes PresentationFramework.dll!System.Windows.Fram eworkTemplate.LoadOptimizedTemplateContent(System.Windows.DependencyObject容器,System.Windows.Markup.IComponentConnector componentConnector,System.Windows.Markup.IStyleConnector styleConnector,System.Collections.Generic.List affectedChildren,System.Windows.UncommonField templatedNonFeChildrenField)+ 0x26a字节 PresentationFramework .dll!System.Windows.FrameworkTemplate.LoadContent(System.Windows.DependencyObject container,System.Collections.Generic.List affectedChildren)+ 0x76 bytes
PresentationFramework.dll!System.Windows.StyleHelper.ApplyTemplateContent(System.Windows.UncommonField dataField ,System.Windows.DependencyObject容器,System.Windows.FrameworkElementFactory templateRoot,int lastChildIndex,System.Collections.Specialized.HybridDictionary childIndexFromChildID,System.Windows.FrameworkTemplate frameworkTemplate)+ 0xc4字节
PresentationFramework.dll!System.Windows.FrameworkTemplate.ApplyTemplateContent(System.Windows.UncommonField templateDataField,System.Windows.FrameworkElement容器)+ 0x3b字节
PresentationFramework.dll!System.Windows.FrameworkElement.ApplyTemplate()+ 0x7b字节
PresentationFramework.dll!System.Windows.FrameworkElement.MeasureCore(System.Windows.Size availableSize)+ 0x40的字节
PresentationCore.dll中!System.Windows.UIElement.Measure(System.Windows.Size availableSize)+ 0x207字节
Xaml:
<DataGrid Margin="80,0,0,0" GridLinesVisibility="None"
RowDetailsVisibilityMode="Collapsed"
ColumnHeaderStyle="{StaticResource ColumnHeaderStyle}"
RowStyle="{StaticResource DataGridRowStyleAlternation}"
AutoGenerateColumns="False" SelectionMode="Single"
AlternationCount="2" Background="Transparent" HeadersVisibility="Column"
x:Name="detailsDatagrid"
Initialized="scenesDetailsDataGrid_Initialized"
ItemsSource="{Binding Source={StaticResource scenesRequisitesViewSource}}"
ColumnDisplayIndexChanged="detailsDatagrid_ColumnDisplayIndexChanged" >
<DataGrid.Columns>
<DataGridTemplateColumn Header="Fahrzeug" Width="SizeToCells">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox DisplayMemberPath="Name"
ItemsSource="{Binding Path=ProjectsRequisites, Source={StaticResource projectsViewSource}, UpdateSourceTrigger=PropertyChanged}"
SelectedValue="{Binding Path=RequisiteId,Mode=TwoWay}"
SelectedValuePath="ID"
SelectionChanged="ComboboxRequisite_SelectionChanged"
Tag="{Binding}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn IsReadOnly="True" Binding="{Binding Path=Costs,StringFormat={}{0:C}, ConverterCulture={x:Static gl:CultureInfo.CurrentCulture}}" Header="Kosten" Width="SizeToCells" />
<DataGridTextColumn Binding="{Binding Path=Count}" Header="Anzahl" Width="SizeToHeader" />
</DataGrid.Columns>
</DataGrid>