XAMLデザイナデザインビューは、例外が値はnullにはできません。パラメータ名:キー(唯一のXAMLデザイナーのデザインビューで発生)
を投げた
示し例外ArgumentNullException:値をNullにすることはできません。
パラメータ名:キー
のStackTraceが(写真の後を参照)
のInnerException:なし
私はから私を防ぎ、次の問題、上の数日間に苦労されているすべての影響を受けるビューでXAML Designe rのデザインビューを使用します。
昨日、私は最終的にそれが唯一の設計時に発生し、それがジェネリック型とDataGridののItemsSourceプロパティ(System.Windows間conflitだから、それは難しいparticularyトレースするには、この奇妙な振る舞いを隔離するために管理しましたコントロール)。
だから、これはデザインビュー
System.Collections.Generic.Dictionary 2.FindEntry(TKey key) at System.Collections.Generic.Dictionary
2.TryGetValueで
(処理鍵キー、TValue & 値)で上に示されているものです System.Windows.Controls.DataGridItemAttachedStorage.TryGetValue(オブジェクト アイテム、DependencyPropertyプロパティ、オブジェクト&値) System.Windows.Cont でSystem.Windows.Controls.DataGridRow.PrepareRow(対象項目、データグリッド owningDataGrid)で System.Windows.Controls.DataGridRow.SyncPropertiesでrols.DataGridRow.RestoreAttachedItemValue(のDependencyObject objectWithProperty、たDependencyPropertyプロパティ)(ブール forcePrepareCells) System.WindowsでSystem.Windows.Controls.ItemsControl.MS.Internal.Controls.IGeneratorHost.PrepareItemContainer(のDependencyObject コンテナ、対象項目)でSystem.Windows.Controls.DataGrid.PrepareContainerForItemOverride(のDependencyObject 要素、対象項目)。プロパティ。 System.Windows.Controls.VirtualizingStackPanel.AddContainerFromGenerator(のInt32 childIndexに、UIElementの子、ブールnewlyRealized、ブール isBeforeViewportで System.Windows.Controls.VirtualizingStackPanel.InsertContainer(のInt32 childIndexに、UIElementのコンテナ、ブールisRecycled)でコンテナ) ) でSystem.Windows.Controls.VirtualizingStackPanel。MeasureChild(IItemContainerGenerator & 発電機、IContainItemStorage & itemStorageProvider、 IContainItemStorage & parentItemStorageProvider、& parentItem、 ブール& hasUniformOrAverageContainerSizeBeenSet、ダブル& オブジェクトcomputedUniformOrAverageContainerSize、 &ダブルcomputedUniformOrAverageContainerPixelSize、ブール& computedAreContainersUniformlySized、IListの&項目、オブジェクト&アイテム、 のIList &子供、Int32 & childIndexに、ブール& visualOrderChanged、 ブール& isHorizontal、サイズ& childConstraint、Rectを&ビューポート、ダブル VirtualizationCacheLength & cacheSizeの、VirtualizationCacheLengthUnit & cacheUnit、ブール& foundFirstItemInViewport、& firstItemInViewportOffset、サイズ& stackPixelSize、サイズ& stackPixelSizeInViewport、サイズ& stackPixelSizeInCacheBeforeViewport、 サイズ& stackPixelSizeInCacheAfterViewport、サイズ& stackLogicalSize、 サイズ& stackLogicalSizeInViewport、サイズ& stackLogicalSizeInCacheBeforeViewport、サイズ& stackLogicalSizeInCacheAfterViewport、ブール& mustDisableVirtualization、ブールisBeforeFirstItem、ブール isAfterFirstItem、ブールisAfterLastItem、ブールskipActualMeasure、 ブールskipGeneration、ブール& hasBringIntoViewContainerBeenMeasured、ブール& hasVirtualizingChildren) at System.Windows.Controls.VirtualizingStackPanel.MeasureOverrideImpl(サイズ const raint、NULL可能 previouslyMeasuredOffsets、Nullable`1 & lastPagePixelSize、ブール 再測定) System.Windows.Controls.VirtualizingStackPanel.MeasureOverride(サイズ 制約)で System.Windows.Controls.Primitives.DataGridRowsPresenter.MeasureOverride(サイズで System.Windows.UIElement.UpdateLayoutでSystem.Windows.ContextLayoutManager.UpdateLayout()でSystem.Windows.UIElement.Measure(サイズ availableSize)(AT System.Windows.FrameworkElement.MeasureCore(サイズ availableSize)で 制約) )
MyViewModelbase.cs(これは私の一般的なビューモデルベース)
namespace BugProof.ViewModels
{
using System.Collections.Generic;
public class MyViewModelBase<TItem> where TItem : class
{
public List<TItem> Items { get; set; }
public MyViewModelBase() { }
}
}
MyExtendedViewModel。CS(文字列タイプに基づいてされます。この私の拡張ビューモデル、)
namespace BugProof.ViewModels
{
public class MyExtendedViewModel : MyViewModelBase<string>
{
public MyExtendedViewModel()
{
}
}
}
MainWindow.xaml
<Window x:Class="BugProof.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="clr-namespace:BugProof.ViewModels"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:BugProof"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance {x:Type vm:MyExtendedViewModel}, IsDesignTimeCreatable=False}"
Title="MainWindow" Height="350" Width="525">
<StackPanel>
<TextBlock>This is what you should se in the designer</TextBlock>
<!--Try replacing following DataGrid by a ListBox or ListView-->
<DataGrid ItemsSource="{Binding Items}"/>
</StackPanel>
</Window>
背後MainWindow.xaml.cs(メインウィンドウのコード)
複合体tary詳細:1がリストボックスによってのDataGridコントロールを置き換えた場合の動作は発生しません
- 、ListViewコントロールまたはのItemsControl
- 私はのVisual Studio 2015、バージョン14.0.25431.01アップデートを使用しています3
- プロジェクトの対象はです.Net Framework 4.5
コレクションに静的でないデフォルト値を使用しようとしましたか? ()=>新しいリスト())? –
戻り値がnullであるかどうかを取得するときにテストする必要があります。 – Safe
こんにちは@ Geert van Horrik。非静的なデフォルト値で試してみると、同じ結果が得られます。しかし、リストをList でMyViewModelBaseクラスに置き換えると、すべてが機能します。それはジェネリック型との衝突です。 –