如果我将事件处理程序添加到组合框,例如SelectionChanged,我会遇到异常。谁能告诉我为什么。
奇怪的行为,因为在我的笔记本电脑上安装了带有 VS2010 的 win7 时,它运行成功。
例外:
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 字节
PresentationFramework.dll!System.Windows.FrameworkTemplate.LoadTemplateXaml(System.Xaml.XamlObjectWriter objectWriter) + 0x66 字节 PresentationFramework.dll!System.Windows.FrameworkTemplate.LoadOptimizedTemplateContent(System.Windows.DependencyObject 容器, System.Windows.Markup.IComponentConnector componentConnector, System.Windows.Markup.IStyleConnector styleConnector, System.Collections.Generic.List 受影响的Children, System.Windows.UncommonField templatedNonFeChildrenField) + 0x26a 字节 PresentationFramework.dll!System.Windows.FrameworkTemplate.LoadContent(System.Windows.DependencyObject 容器, System.Collections .Generic.List affectedChildren) + 0x76 字节
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 字节
xml:
<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>