WPF, 'Object reference not set to an instance of an object' in Designer

后端 未结 8 2232
一个人的身影
一个人的身影 2020-12-01 08:58

I\'m getting an \"Object reference not set to an instance of an object\" error when I try to reload the Designer for my XAML UserControl. Visual Studio highlig

相关标签:
8条回答
  • 2020-12-01 09:57

    I was able to solve the problem after giving a name to an object. It is VS2015, and my markup is different, but it could help somebody too:

    <ResourceDictionary>
        <DataTemplate x:Key="ThisKeySolvesDesignersNullRef" 
                        DataType="local:MyViewModel">
            <local:MyControl/>
        </DataTemplate>
    </ResourceDictionary>
    
    0 讨论(0)
  • 2020-12-01 10:00

    In Visual Studio 2015 for WPF:

    1. Hover with your mouse over the "Object reference not set to an instance of an object" in the Design view.
    2. Wait a (few) second(s) and you will see a popup
    3. Select "View Exception Details" (you will also see "View Code" and "Delete this element"
    4. This dialog will show you the exception and the StackTrace

    Hope this helps.

    If you do this on the XAML you will just see the exception but not the popup with "View Exception Details", thus you need to do it in the Designer/Design view.

    0 讨论(0)
提交回复
热议问题