1

The error happens when i included my own usercontrol in this line (drag & drop):

<my:ItemParte x:Name="UcItemParte" Panel.ZIndex="6" />

and the error says: "Object reference not set to an instance of an object."

And I don´t know why... any help?

UPDATE: This is the Sub New()

Shared Sub New() ListViewFontSizeProperty = DependencyProperty.Register("ListViewFontSize", _ GetType(Double), GetType(ItemParte)) End Sub

Public Sub New()
    Try
        mModeloItem = Modelo_Item.Instance
        mModeloParte = Modelo_Parte.Instance
        mModeloParteLinea = Modelo_Parte_Linea.Instance

        ' Llamada necesaria para el Diseñador de Windows Forms.
        InitializeComponent()

        ' Agregue cualquier inicialización después de la llamada a InitializeComponent().
        If Not IsInDesignMode Then
            mTextos = Textos.Instance
            mConfig = Config.Instance

            MainWin = My.Application.MainWindow

            AddHandler MainWin.VentanaMensaje.ButtonAceptarExec, AddressOf VentanaMensaje_AceptarClickCallback

            AddHandler MainWin.Fuentes.PropertyChanged, AddressOf Fuentes_PropertyChanged

            MainWin.Fuentes.RecargarFontSize()

        End If

    Catch ex As Exception
        My.Log.WriteEntry(ex.Message, TraceEventType.Critical)
    End Try
End Sub
Kioko Kiaza
  • 1,378
  • 8
  • 28
  • 57

2 Answers2

0

The error might be that you have something doing inside your Load event of the user control - this event fires even when form is loaded for use by designer, not only in runtime.

If that's the case, than in your Load method add

if (!System.ComponentModel.DesignerProperties.GetIsInDesignMode)
{
  // ...your code
}

as explained here

Community
  • 1
  • 1
veljkoz
  • 8,384
  • 8
  • 55
  • 91
  • Thanks for you answer but i don´t have any code on the load event – Kioko Kiaza Nov 10 '10 at 15:21
  • Do you have any code inside the constructor for your ItemParte control? – Judah Gabriel Himango Nov 10 '10 at 15:55
  • Shared Sub New() ListViewFontSizeProperty = DependencyProperty.Register("ListViewFontSize", _ GetType(Double), GetType(ItemParte)) End Sub – Kioko Kiaza Nov 10 '10 at 16:02
  • and also Public Sub New() InitializeComponent() If Not IsInDesignMode Then mTextos = Textos.Instance mConfig = Config.Instance MainWin = My.Application.MainWindow AddHandler MainWin.VentanaMensaje.ButtonAceptarExec, AddressOf VentanaMensaje_AceptarClickCallback AddHandler MainWin.Fuentes.PropertyChanged, AddressOf Fuentes_PropertyChanged MainWin.Fuentes.RecargarFontSize() End If End Sub – Kioko Kiaza Nov 10 '10 at 16:03
0

This was the solution http://www.forkcan.com/viewcode/186/-IsInDesignMode-for-WPF-and-Silverlight

Kioko Kiaza
  • 1,378
  • 8
  • 28
  • 57