3

我在 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)在 System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo 方法,对象目标,Object[] 参数,签名 sig,MethodAttributes methodAttributes , RuntimeType typeOwner) 在 System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] 参数, CultureInfo 文化, Boolean skipVisibilityChecks) 在 System.Delegate.DynamicInvokeImpl(Object[] args) 在 System.Windows。 Threading.ExceptionWrapper.InternalRealCall(委托回调,对象参数,

System.ArgumentNullException 值不能为空。在 System.RuntimeType.MakeGenericType(Type[] 实例化) 在 Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkUtil.GetRuntimeType(Type type) 在 Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkType.TryGetRuntimeType() 在 Microsoft.VisualStudio.Shell.Design .VsTargetFrameworkUtil.EnsureRuntimeType(Type type) 在 Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkProvider.GetRuntimeType(Type reflectionType) 在 MS.Internal.Package.VSIsolationProviderService.RemoteReferenceProxy.VsReflectionResolver.GetRuntimeType(Type reflectionType) 在 Microsoft.Windows.Design.Metadata Microsoft.Windows.Design.Metadata.ReflectionMetadataContext.Microsoft.Windows.Design 中的 .ReflectionMetadataContext.CachingReflectionResolver.GetRuntimeType(类型反射类型)。1.Microsoft.Windows.Design.Metadata.Reflection.IReflectionMember.get_MemberInfo() at MS.Internal.Metadata.ClrType.Equals(Object obj) at System.Collections.Generic.ObjectEqualityComparer1.Equals(T x, T y)
在 System.Collections.Concurrent.ConcurrentDictionary 2.TryGetValue(TKey key, TValue& value) at Microsoft.Windows.Design.Metadata.Xaml.XamlExtensionImplementations.XamlMemberFor[TMember,TXaml](TMember member, Factory2 工厂)在 MS.Internal.Design.Metadata.Xaml.XamlType.d_ 7.MoveNext() 在 MS.Internal.Design.Metadata.Xaml .XamlType.d _0.MoveNext() 在 Microsoft.Windows.Design.Metadata.Xaml.XamlExtensionImplementations.d_ 7.MoveNext() 在 MS.Internal.VirtualModel.VirtualModelPropertyCollection.d _0.MoveNext() 在 System.Linq.Buffer1..ctor(IEnumerable1 来源)在 System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 来源)在 MS.Internal.VirtualModel.VirtualModelPropertyCollection.GetEnumerator() 在 MS.Internal.Designer.PropertyEditing.Model.Properties.ModelPropertyMerger.d__0.MoveNext () 在 MS.Internal.Designer.PropertyEditing.PropertyInspector.UpdateCategories 的 MS.Internal.Designer.PropertyEditing.PropertyInspector.UpdateCategories(IPropertyViewManager viewManager, 选择选择, Boolean attachOnly, IEventCodeBehindProxy eventCodeBehindProxy, CategoryList categoryList) , IEntryReader entryReader) 在 MS.Internal.Designer.PropertyEditing.PropertyInspector.RefreshPropertyList(Boolean attachOnly) 在 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; }
    }
    
4

1 回答 1

1

这是一个 M$已经确认Visual Studio SP1 错误的问题。卸载 SP1 并在为我解决它之后愉快地工作。这是非常不令人满意的,也是微软礼服的另一个耻辱,但是有什么选择呢?

于 2012-04-26T09:16:18.767 回答