2017-03-15 10 views
1

XAML 디자이너 디자인 뷰는 예외가값은 null 일 수 없습니다. 매개 변수 이름 : 키 (만 XAML 디자이너의 디자인 뷰에서 발생)

을 던져졌다

보여줍니다 경우 ArgumentNullException : 값 null 일 수 없습니다.

매개 변수 이름 : 키

스택 트레이스가 (사진 후에 참조)

의 InnerException : 없음

내가 나를 방지 다음 문제에 며칠 동안 고전을 면치 못하고있다

영향을받는 모든보기에서 XAML Designe r의 디자인보기를 사용합니다.

어제, 나는 결국은 디자인 타임에 발생하고, 그 일반적인 유형과 데이터 그리드의 ItemsSource 속성 (System.Windows 사이 conflit을 보이기 때문에, 열심히 particulary 추적이 이상한 행동을 분리 관리 .통제 수단).

그래서, 이것은 디자인보기

System.Collections.Generic.Dictionary 2.FindEntry(TKey key) at System.Collections.Generic.Dictionary 2.TryGetValue에서 enter image description here

(TKEY 키, 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에서 System.Windows.Controls.DataGrid.PrepareContainerForItemOverride (DependencyObject에 요소, 개체 항목) (DependencyObject에 컨테이너 개체 항목). Controls.ItemContainerGenerator.System.Windows.Controls.Primitives.IItemContainerGenerator.PrepareItemContainer (종속성 개체 System.Windows.Controls.VirtualizingStackPanel.InsertContainer에서 컨테이너)에 System.Windows.Controls.VirtualizingStackPanel.AddContainerFromGenerator (INT32 childIndex에, 컨테이너의 UIElement 부울 isRecycled) (INT32 childIndex에, 아이의 UIElement 부울 newlyRealized 부울 isBeforeViewport) at System.Windows.Controls.VirtualizingStackPanel.MeasureChild (IItemContainerGenerator & 발전기, IContainItemStorage & itemStorageProvider, & parentItemStorageProvider는, & parentItem, 부울 & hasUniformOrAverageContainerSizeBeenSet 객체 IContainItemStorage, 더블 & computedUniformOrAverageContainerSize, 더블 & computedUniformOrAverageContainerPixelSize, 부울 & computedAreContainersUniformlySized은 IList & 항목, 객체 & 항목 은 IList & 어린이, Int32 & childIndex에, 부울 & visualOrderChanged, 부울 & isHorizontal, 크기 & childConstraint, 사각형 & 뷰포트, 더블 VirtualizationCacheLength & CACHESIZE, VirtualizationCacheLengthUnit & cacheUnit, 부울 & foundFirstItemInViewport, & firstItemInViewportOffset, 크기 & stackPixelSize, 크기 & stackPixelSizeInViewport, 크기 & 크기 : & stackPixelSizeInCacheBeforeViewportstackLogicalSize, 크기 & 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.Primitives.DataGridRowsPresenter.MeasureOverride에서 System.Windows.Controls.VirtualizingStackPanel.MeasureOverride (크기 제약)에서 부울 재 측정) (크기 System.Windows.UIElement.UpdateLayout에서 System.Windows.ContextLayoutManager.UpdateLayout()에서 System.Windows.UIElement.Measure (크기 availableSize) (에서 System.Windows.FrameworkElement.MeasureCore (크기 availableSize)에서 제약))

Sample project source code

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 (A 문자열 유형에 따라 될 것이 내 확장 된 뷰 모델)

namespace BugProof.ViewModels 
{ 
    public class MyExtendedViewModel : MyViewModelBase<string> 
    { 
     public MyExtendedViewModel() 
     { 
     } 
    } 
} 

MainWindow.xaml

MainWindow.xaml.cs를 (MainWindow를의 코드 뒤에

<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> 
)

Complemen TARY 세부 정보 : 하나는 목록 상자에 의해 데이터 그리드 제어를 대체하는 경우 문제가 발생하지 않습니다

  • , ListView에 또는 ItemsControl에
  • 내가 비주얼 스튜디오 2015 버전 14.0.25431.01 업데이트를 사용하고 있습니다 3
  • 프로젝트의 대상은 입니다 .Net Framework 4.5
+1

컬렉션에 정적이 아닌 기본값을 사용하려고 했습니까? 예 :() => 새 목록 ())? –

+0

반환 값이 null이거나 아닌 경우 get 할 때 테스트해야한다고 생각합니다. – Safe

+0

안녕하세요 @ Geert van Horrik.정적이 아닌 기본값으로 시도 할 때 동일한 결과를 얻습니다. 그러나 List 을 List 으로 바꾸면 MyViewModelBase 클래스에 모든 것이 작동합니다. 제네릭 유형과 충돌하는 것 같습니다. –

답변

4

설정 IsDesignTimeCreatable =이 코드는 디자인 타임에 실행 여부 확인, 뷰 모델의 매개 변수가없는 생성자를 구현하는 특별한주의를 필요로하지만, 속임수를 썼는지 MainWindows.xaml 사실. IsDesignTimeCreatable = 진정한 설정

According to Microsoft

는 "설계 인스턴스가 대신 디자이너에서 생성 한 대체 유형, 당신의 유형에서 생성되도록 지정합니다." IsDesignTimeCreatable가 설정 또는 거짓로 설정되어있는 경우

놀랍게도, 또한 according to Microsoft은 "모든 디자인 도구는 바인딩 속성에 대한 클래스를 구문 분석입니다 않습니다".

나는 두 개의 정반대의 진리를 가지고 있다고 생각합니다. 두 경우 모두 문맥에 따라 실제로 사실 일 수 있습니다. 할 수있다, 두 번째 소스는 문서 작성시에, XAML 디자이너가 자동으로 (IEnumerable을) 재산

을까지 IsDesignTimeCreatable는이 컬렉션을 발견 할 때마다, 거짓 값을 기본값으로 설정되면 생성하는 3 개 샘플 인식하지 않았다 증거 그렇지 않으면,이 우리가 리스트 박스, ListView에 의해 데이터 그리드 컨트롤을 대체 할 경우이 질문에 문제가 발생하지 않기 때문에 ItemsSourceIsDesignTimeCreatable = 거짓을 일반적인 수집 소스에 바인더 제본하고있는 WPF 데이터 그리드 제어 버그입니다 또는 ItemsControls.