私の WPF アプリケーションでは、それぞれTabItem
が異なるものをロードしますUserControl
。MainWindow のデザイン ビューでは、aUserControl
を aにロードしているときに、下の画像のようにTabItem
表示されAn unhandeled exception has occured
ます。
XAML:
<TabItem Header="Catalog" Name="catalog" MinWidth="150" Width="auto" >
<my:CatelogControl x:Name="catelogControl" Margin="1,0" Width="800"/>
</TabItem>
プロジェクトをデバッグするとNullReferecneException was unhandeled
、下の画像のように表示されます。
カテゴリユーザー コントロール:
<UserControl x:Class="LibraryAutomation.UserControls.CatalogControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:app="clr-namespace:LibraryAutomation"
Name="catalogControl"
mc:Ignorable="d" Loaded="catalogControl_Loaded"
d:DesignHeight="480" d:DesignWidth="846">
<UserControl.Resources>
<app:CopyLeftConverter x:Key="copyLeftConverter" />
<DataTemplate x:Key="CourseTemplate">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=CourseID}"/>
<TextBlock Text=" : "/>
<TextBlock Text="{Binding Path=CourseName}"/>
</StackPanel>
</DataTemplate>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Height="481">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="0.4*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition MinHeight="400" Height="476"></RowDefinition>
<RowDefinition Height="4*" />
</Grid.RowDefinitions>
<StackPanel Height="460" Margin="0,0,241,0" Grid.ColumnSpan="2">
<ComboBox Name="courseList" VerticalAlignment="Top" SelectionChanged="courseList_SelectionChanged" IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding}" ItemTemplate="{StaticResource CourseTemplate}"/>
<ListView MinHeight="400" Height="400" Name="bookList" IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding}" KeyDown="bookList_KeyDown" KeyUp="bookList_KeyDown" MouseEnter="bookList_MouseEnter" MouseDoubleClick="bookList_MouseDoubleClick" MouseDown="bookList_MouseDoubleClick" MouseUp="bookList_MouseDoubleClick">
<ListView.View>
<GridView>
<GridView.Columns>
<GridViewColumn Width="auto" Header="Book ID" DisplayMemberBinding="{Binding Path=BookID}"/>
<GridViewColumn Width="auto" Header="Book Name" DisplayMemberBinding="{Binding Path=BookName}"/>
<GridViewColumn Width="auto" Header="Author" DisplayMemberBinding="{Binding Path=Author}"/>
<GridViewColumn Width="auto" Header="Publisher" DisplayMemberBinding="{Binding Path=Publisher}"/>
<GridViewColumn Width="auto" Header="Remaining Qunatity" DisplayMemberBinding="{Binding Path=QuantityLeft, Converter={StaticResource copyLeftConverter}}"/>
<GridViewColumn Width="auto" Header="Total Quantity" DisplayMemberBinding="{Binding Path=TotalQuantity, Converter={StaticResource copyLeftConverter}}"/>
</GridView.Columns>
</GridView>
</ListView.View>
</ListView>
<DockPanel>
<Button Width="150" Height="30" Margin="5" Content="New Book" Name="newBook" Click="newBook_Click" HorizontalAlignment="Center"/>
<Button Width="150" Height="30" Margin="5" Content="Save Changes" Name="saveChanges" Click="saveChanges_Click" IsEnabled="False" HorizontalAlignment="Right"/>
</DockPanel>
</StackPanel>
<StackPanel Grid.Column="1" Grid.Row="0" HorizontalAlignment="Left">
<Image Height="150" Width="120" Source="/LibraryAutomation;component/Images/Books.jpg"/>
<StackPanel Orientation="Horizontal">
<Label Height="26" Width="auto" HorizontalAlignment="Left">ID:</Label>
<TextBlock Width="123" Padding="10,5" Name="previewBookId"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label Height="26" Width="auto" HorizontalAlignment="Left">Title :</Label>
<TextBlock Padding="10,5" Name="previewBookName" HorizontalAlignment="Left" Width="103" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label Height="26" Width="auto" HorizontalAlignment="Left">Author :</Label>
<TextBlock Padding="10,5" Name="previewAuthor" HorizontalAlignment="Left" Width="100" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label Height="26" Width="auto" HorizontalAlignment="Left">Publisher :</Label>
<TextBlock Padding="10,5" Name="previewPublisher" HorizontalAlignment="Left" Width="88" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label Height="26" Width="auto" HorizontalAlignment="Left">ISBN :</Label>
<TextBlock Padding="10,5" Name="previewIsbn" HorizontalAlignment="Left" Width="107" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label Height="26" Width="auto" HorizontalAlignment="Left">Quantity :</Label>
<TextBlock Padding="10,5" Name="previewTotalCopy" HorizontalAlignment="Left" Width="90" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label Height="26" Width="auto" HorizontalAlignment="Left">Remaining:</Label>
<TextBlock Padding="10,5" Name="previewCopyLeft" HorizontalAlignment="Left" Width="84" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label Height="26" Width="auto" HorizontalAlignment="Left">Location :</Label>
<TextBlock Padding="10,5" Name="previewLocation" HorizontalAlignment="Left" Width="92" />
</StackPanel>
<Separator/>
<Button Width="150" Height="30" Name="hireThisBook" Click="hireThisBook_Click"> Hire</Button>
<Separator/>
<Button Margin="10" Width="100" Height="20" Name="editThisBook" Click="editThisBook_Click"> Edit</Button>
<Button Margin="10" Width="100" Height="20" Name="deleteThisBook" Click="deleteThisBook_Click">Delete</Button>
</StackPanel>
</Grid>
編集:詳細の例外、
System.NullReferenceException
Object reference not set to an instance of an object.
at System.Data.Linq.SqlClient.QueryConverter.VisitInvocation(InvocationExpression invoke)
at System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node)
at System.Data.Linq.SqlClient.QueryConverter.VisitExpression(Expression exp)
at System.Data.Linq.SqlClient.QueryConverter.VisitJoin(Expression outerSequence, Expression innerSequence, LambdaExpression outerKeySelector, LambdaExpression innerKeySelector, LambdaExpression resultSelector)
at System.Data.Linq.SqlClient.QueryConverter.VisitSequenceOperatorCall(MethodCallExpression mc)
at System.Data.Linq.SqlClient.QueryConverter.VisitMethodCall(MethodCallExpression mc)
at System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node)
at System.Data.Linq.SqlClient.QueryConverter.VisitWhere(Expression sequence, LambdaExpression predicate)
at System.Data.Linq.SqlClient.QueryConverter.VisitSequenceOperatorCall(MethodCallExpression mc)
at System.Data.Linq.SqlClient.QueryConverter.VisitMethodCall(MethodCallExpression mc)
at System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node)
at System.Data.Linq.SqlClient.QueryConverter.VisitSelect(Expression sequence, LambdaExpression selector)
at System.Data.Linq.SqlClient.QueryConverter.VisitSequenceOperatorCall(MethodCallExpression mc)
at System.Data.Linq.SqlClient.QueryConverter.VisitMethodCall(MethodCallExpression mc)
at System.Data.Linq.SqlClient.QueryConverter.VisitInner(Expression node)
at System.Data.Linq.SqlClient.QueryConverter.ConvertOuter(Expression node)
at System.Data.Linq.SqlClient.SqlProvider.BuildQuery(Expression query, SqlNodeAnnotations annotations)
at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query)
at System.Data.Linq.DataQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at System.Data.Linq.Provider.BindingList.Create[T](DataContext context, IEnumerable`1 sequence)
at System.Data.Linq.DataQuery`1.GetNewBindingList()
at System.Data.Linq.DataQuery`1.System.ComponentModel.IListSource.GetList()
at MS.Internal.Data.ViewManager.GetViewRecord(Object collection, CollectionViewSource cvs, Type collectionViewType, Boolean createView)
at MS.Internal.Data.DataBindEngine.GetViewRecord(Object collection, CollectionViewSource key, Type collectionViewType, Boolean createView)
at System.Windows.Data.CollectionViewSource.GetDefaultCollectionView(Object source, Boolean createView)
at System.Windows.Data.CollectionViewSource.GetDefaultCollectionView(Object source, DependencyObject d)
at System.Windows.Controls.ItemCollection.SetItemsSource(IEnumerable value)
at System.Windows.Controls.ItemsControl.OnItemsSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
at System.Windows.DependencyObject.InvalidateProperty(DependencyProperty dp)
at System.Windows.Data.BindingExpressionBase.Invalidate(Boolean isASubPropertyChange)
at System.Windows.Data.BindingExpression.TransferValue(Object newValue, Boolean isASubPropertyChange)
at System.Windows.Data.BindingExpression.Activate(Object item)
at System.Windows.Data.BindingExpression.AttachToContext(AttachAttempt attempt)
at System.Windows.Data.BindingExpression.MS.Internal.Data.IDataBindEngineClient.AttachToContext(Boolean lastChance)
at MS.Internal.Data.DataBindEngine.Task.Run(Boolean lastChance)
at MS.Internal.Data.DataBindEngine.Run(Object arg)
at MS.Internal.Data.DataBindEngine.OnLayoutUpdated(Object sender, EventArgs e)
at System.Windows.ContextLayoutManager.fireLayoutUpdateEvent()
at System.Windows.ContextLayoutManager.UpdateLayout()
at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)
at System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork()
at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
View details では、InnerException に「null」と表示され、何が問題なのかわかりませんでした。何か提案はありますか?ありがとうございました。