为什么我在wpf的xaml查看器中遇到此异常?

时间:2012-04-18 10:41:11

标签: wpf

我在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&amp; SIG,   MethodAttributes methodAttributes,RuntimeType typeOwner)at   System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo方法,   Object target,Object []参数,Signature sig,MethodAttributes   methodAttributes,RuntimeType typeOwner)at   System.Reflection.RuntimeMethodInfo.Invoke(Object obj,BindingFlags   invokeAttr,Binder binder,Object []参数,CultureInfo文化,   布尔值skipVisibilityChecks)at   System.Delegate.DynamicInvokeImpl(Object [] args)at   System.Windows.Threading.ExceptionWrapper.InternalRealCall(代表   回调,对象args,Int32 numArgs)at   MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(对象   source,Delegate方法,Object args,Int32 numArgs,Delegate   catchHandler)

     

System.ArgumentNullException值不能为null。在   System.RuntimeType.MakeGenericType(Type [] instantiation)at   Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkUtil.GetRuntimeType(类型   输入)   Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkType.TryGetRuntimeType()   在   Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkUtil.EnsureRuntimeType(类型   输入)   Microsoft.VisualStudio.Shell.Design.VsTargetFrameworkProvider.GetRuntimeType(类型   reflectionType)at   MS.Internal.Package.VSIsolationProviderService.RemoteReferenceProxy.VsReflectionResolver.GetRuntimeType(类型   reflectionType)at   Microsoft.Windows.Design.Metadata.ReflectionMetadataContext.CachingReflectionResolver.GetRuntimeType(类型   reflectionType)at   Microsoft.Windows.Design.Metadata.ReflectionMetadataContext.Microsoft.Windows.Design.Metadata.IReflectionResolver.GetRuntimeType(类型   在MS.Internal.Metadata.ClrType.get_RuntimeMember()的reflectionType)   在   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)
  在   System.Collections.Concurrent.ConcurrentDictionary 2.TryGetValue(TKey key, TValue& value) at Microsoft.Windows.Design.Metadata.Xaml.XamlExtensionImplementations.XamlMemberFor[TMember,TXaml](TMember member, Factory 2工厂)at   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.Buffer 1..ctor(IEnumerable 1来源)at   System.Linq.Enumerable.ToArray [TSource](IEnumerable`1 source)at at   MS.Internal.VirtualModel.VirtualModelPropertyCollection.GetEnumerator()   在   MS.Internal.Designer.PropertyEditing.Model.Properties.ModelPropertyMerger.d__0.MoveNext()   在   MS.Internal.Designer.PropertyEditing.Views.PropertyEntryReader.RedraftEntries(IPropertyViewManager   viewManager,选择选择,布尔attachOnly,   IEventCodeBehindProxy eventCodeBehindProxy,CategoryList categoryList)   在   MS.Internal.Designer.PropertyEditing.PropertyInspector.UpdateCategories(选择   selection,Boolean attachedOnly,IEntryReader entryReader)at   MS.Internal.Designer.PropertyEditing.PropertyInspector.RefreshPropertyList(布尔   在附近   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; }
    }
    

1 个答案:

答案 0 :(得分:1)

这是一个问题M $ has already confirmed一个Visual Studio SP1错误。卸载SP1后,为我解决后,工作愉快。这是非常令人不满意的,而且是微软长袍的另一个耻辱,但有哪些选择呢?