{ BusinessLogic admintasks = new BusinessLo...">

"Unable to instantiate error in WPF XAML

I have an open class

public class FCabinetNames:List<string> { BusinessLogic admintasks = new BusinessLogic(); public FCabinetNames() { try { List<CabinetData> cab1 = admintasks.CabinetDataforGrid(); foreach (var c1 in cab1) { this.Add(c1.CabinetName); } } catch { } } } 

Now on the xaml page, when I try to add this class as a static resource, I get "cannot create an instance", as shown below enter image description here

Please guide.

UPDATE:

I missed an important point. The application compiles fine, and the xaml page also loads fine. I planned to use this as a data source and is expected to remain empty.

+7
c # wpf xaml
source share
1 answer

I have had similar problems in the past. In most cases, its components and links that the user class is trying to load.

The two-step solution that works most often for me:

  • Move the constructor of your custom class to another function, then call this function in the constructor of your list (or class)
  • Add to the next function call in the constructor, but after the Initialize component. (I use this for custom controls and is not really valid in your case, but depending on how you set up the content. This may be useful).

 if (System.ComponentModel.DesignerProperties.GetIsInDesignMode(this)) return; 

Both steps help the xaml developer download components that may have problems with being in a debug state. @Heinzi pretty much argues with β€œsomething”, throwing errors, usually (in my experience), they buried something that you did not expect.

+9
source share

All Articles