私はこれをxamlファイルに持っています:
<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>
デザインモードでは、xamlファイルのエラーが常に表示されますが、実行できます。
System.Reflection.TargetInvocationException呼び出しのターゲットによって例外がスローされました。System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfoメソッド、オブジェクトターゲット、Object []引数、SignatureStruct&sig、MethodAttributes methodAttributes、RuntimeType typeOwner)at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfoメソッド、オブジェクトターゲット、Object []引数、署名sig、MethodAttributes methodAttributes 、RuntimeType typeOwner)at System.Reflection.RuntimeMethodInfo.Invoke(Object obj、BindingFlags invokeAttr、バインダーバインダー、Object []パラメーター、CultureInfoカルチャー、ブールskipVisibilityChecks)at System.Delegate.DynamicInvokeImpl(Object [] args)atSystem.Windows。 Threading.ExceptionWrapper.InternalRealCall(デリゲートコールバック、オブジェクト引数、
System.ArgumentNullException値をnullにすることはできません。System.RuntimeType.MakeGenericType(Type [] instanceiation)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(TypereflectionType)at MS.Internal.Package.VSIsolationProviderService.RemoteReferenceProxy.VsReflectionResolver.GetRuntimeType(TypereflectionType)at Microsoft.Windows.Design.Metadata Microsoft.Windows.Design.Metadata.ReflectionMetadataContext.Microsoft.Windows.Designの.ReflectionMetadataContext.CachingReflectionResolver.GetRuntimeType(TypereflectionType)。
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ソース)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 attachOnly、IEventCodeBehindProxy eventCodeBehindProxy、CategoryList categoryList)at MS.Internal.Designer.PropertyEditing.PropertyInspector.UpdateCategories(Selection selection、Boolean attachOnly 、IEntryReader entryReader)at MS.Internal.Designer.PropertyEditing.PropertyInspector.RefreshPropertyList(Boolean attachOnly)at MS.Internal.Designer.PropertyEditing.PropertyInspector.OnSelectionChangedIdle()
更新しました:
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; } }