I have this in xaml file:
<Window x:Class="TestTool.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:RecoConfigTool="clr-namespace:TestTool" Title="Window1" Height="300" Width="300">
<Grid>
<ItemsControl ItemsSource="{Binding Parents}">
</ItemsControl>
</Grid>
<Window.Resources>
<DataTemplate DataType="{x:Type RecoConfigTool:Parent}">
<StackPanel>
<TextBox Text="{Binding Name}"/>
<ListView ItemsSource="{Binding Childs}"/>
</StackPanel>
</DataTemplate>
<DataTemplate DataType="{x:Type RecoConfigTool:Child}">
<StackPanel Orientation="Horizontal">
<TextBox Text="{Binding Name}"/>
<TextBox>,</TextBox>
<TextBox Text="{Binding Age}"/>
</StackPanel>
</DataTemplate>
</Window.Resources>
</Window>
In design mode I always see the error of the xaml file but I can run it:
System.Reflection.TargetInvocationException Exception has been thrown by the target of an invocation. at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner) at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) at System.Delegate.DynamicInvokeImpl(Object[] args) 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)
System.ArgumentNullException Value cannot be null. at System.RuntimeType.MakeGenericType(Type[] instantiation) at Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkUtil.GetRuntimeType(Type type) at Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkType.TryGetRuntimeType() at Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkUtil.EnsureRuntimeType(Type type) at Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkProvider.GetRuntimeType(Type reflectionType) at MS.Internal.Package.VSIsolationProviderService.RemoteReferenceProxy.VsReflectionResolver.GetRuntimeType(Type reflectionType) at Microsoft.Windows.Design.Metadata.ReflectionMetadataContext.CachingReflectionResolver.GetRuntimeType(Type reflectionType) at Microsoft.Windows.Design.Metadata.ReflectionMetadataContext.Microsoft.Windows.Design.Metadata.IReflectionResolver.GetRuntimeType(Type reflectionType) at MS.Internal.Metadata.ClrType.get_RuntimeMember() at MS.Internal.Metadata.ClrMember
1.Microsoft.Windows.Design.Metadata.Reflection.IReflectionMember.get_MemberInfo() at MS.Internal.Metadata.ClrType.Equals(Object obj) at System.Collections.Generic.ObjectEqualityComparer
1.Equals(T x, T y)
at System.Collections.Concurrent.ConcurrentDictionary2.TryGetValue(TKey key, TValue& value) at Microsoft.Windows.Design.Metadata.Xaml.XamlExtensionImplementations.XamlMemberFor[TMember,TXaml](TMember member, Factory
2 factory) at MS.Internal.Design.Metadata.Xaml.XamlType.d_7.MoveNext() at MS.Internal.Design.Metadata.Xaml.XamlType.d_0.MoveNext() at Microsoft.Windows.Design.Metadata.Xaml.XamlExtensionImplementations.d_7.MoveNext() at MS.Internal.VirtualModel.VirtualModelPropertyCollection.d_0.MoveNext() at System.Linq.Buffer1..ctor(IEnumerable
1 source) at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source) at MS.Internal.VirtualModel.VirtualModelPropertyCollection.GetEnumerator() at MS.Internal.Designer.PropertyEditing.Model.Properties.ModelPropertyMerger.d__0.MoveNext() at MS.Internal.Designer.PropertyEditing.Views.PropertyEntryReader.RedraftEntries(IPropertyViewManager viewManager, Selection selection, Boolean attachedOnly, IEventCodeBehindProxy eventCodeBehindProxy, CategoryList categoryList) at MS.Internal.Designer.PropertyEditing.PropertyInspector.UpdateCategories(Selection selection, Boolean attachedOnly, IEntryReader entryReader) at MS.Internal.Designer.PropertyEditing.PropertyInspector.RefreshPropertyList(Boolean attachedOnly) at MS.Internal.Designer.PropertyEditing.PropertyInspector.OnSelectionChangedIdle()
Updated:
public class Parent { public string Name { get; set; } public List<Child> Childs { get; set; } } public class ParentFactory { public List<Parent> Parents { get; set; } public ParentFactory() { var child1 = new Child{Name="Peter", Age=10, Married = true}; var child2 = new Child{ Name = "Mary", Age = 9, Married = false }; var child3 = new Child{ Name = "Becky", Age = 12, Married = false }; var parent1 = new Parent{Name="Adam", Childs = new List<Child>(){child1, child2}}; var parent2 = new Parent{Name="Kevin", Childs = new List<Child>(){child3}}; Parents = new List<Parent>{parent1, parent2}; } } public class Child { public string Name { get; set; } public int Age { get; set; } public bool Married { get; set; } }
RecoConfigTool:Parent
andRecoConfigTool:Child
look like? Are they generic classes? - user7116