BlargleMonster
BlargleMonster

Reputation: 1622

Mysterious Windows.UI.Xaml.Markup.XamlParseException

I'm trying to develop some custom controls (I'm actually using Templated Control to do this if that matters) for a windows app store app. I'm getting a rather ambiguous error (as seen in the title). The only additional information is this:

WinRT information: Cannot create instance of type 'SoundControls.tcNote' [Line: 13 Position: 51]

I'm not sure if the issue is with the Generic.xaml file where the layout of the control is defined (as I would think the error seems to point to) or the code behind file.

Either way, here is line 13 for both:

Generic.xaml

BorderBrush="{TemplateBinding BorderBrush}"

Code Behind

using Windows.UI.Xaml.Controls.Primitives;

Both seem rather meaningless and innocuous. Does anyone have ideas on what to look at closer to solve this error? I am willing to post code snippets and such (as relevant/requested) but I always hate looking at a question and seeing nothing but pages of code.

EDIT:

Constructor as requested:

this.DefaultStyleKey = typeof(tcNote);

(GetTemplateChild("PART_note") as Thumb).DragStarted += tcNote_DragStarted;
(GetTemplateChild("PART_note") as Thumb).DragDelta += tcNote_DragDelta;
(GetTemplateChild("PART_note") as Thumb).DragCompleted += tcNote_DragCompleted;

Second Edit/Solution:

I figured out that the line 13 issue is in MainPage.xaml.

<SoundControls:tcNote HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" />

That line looks like it has an error on it (the blue underline, but it still let me build) and if I hover over it it says "Delegate to an instance method cannot have null 'this'." The issue seems to be that *PART_note* wasn't available yet. I needed to move those lines in the constructor into the OnApplyTemplate method.

Upvotes: 1

Views: 2763

Answers (3)

Mihai Drebot
Mihai Drebot

Reputation: 444

I realize this is an old question. I just stumble into this error, in my case it was because in one language resource i was setting the Text of a Textbox that was also bound to a property in the view model. Of course, there was no clue about this in the exception, the inner exception was closed, and it only showed on the emulator, since the local machine was using another culture. This made it difficult to track down. Maybe this will help some unfortunate soul.

Upvotes: 0

Emond
Emond

Reputation: 50682

When I encounter this error I do two things:

  1. Check the InnerException (repeat this step until it is null) to get a better idea of what is going on. Fix it.

  2. If there is no InnerException (or it is too vague) I comment out all XAML and start slowly bringing it back. This helps to pinpoint the offending XAML or code.

Upvotes: 1

Damir Arh
Damir Arh

Reputation: 17855

Are you maybe instantiating SoundControls.tcNote in some other XAML file at line 13? The error could originate from there.

The problem might be either:

  • in your control's constructor: Are you sure GetTemplateChild("PART_note") as Thumb isn't null? Does it help if you comment out These lines?
  • or somewhere in its XAML: parse error because of unresolvable StaticResource referencesor of some other error.

I would start troubleshooting the issue by minimizing the amount of code / XAML in the control and seeing if the problem goes away.

Upvotes: 0

Related Questions