Answered by:
Resource Dictionary Issues

Question
-
I'm having an issue creating and refrencing Resource Dictionaries. The errors are pretty vague which make it difficult to troubleshoot.
--error
An exception of type 'Windows.UI.Xaml.Markup.XamlParseException' occurred in myApp.exe but was not handled in user code
Additional information: Failed to assign to property '%0'. [Line: 12 Position: 44]
---end
How does one go about troubleshooting these issues. Also, are there any documents available on the 'best practices' on organizing these resources?
A side question - how do you go about getting the default control template for each control?
Thanks!
Saturday, September 24, 2011 4:49 PM
Answers
-
Hi Shaker,
Check out this thread. It uses BaseUri as part of the solution:
-Jeff
Jeff Sanders (MSFT)- Proposed as answer by Jeff SandersMicrosoft employee, Moderator Wednesday, November 30, 2011 2:47 PM
- Marked as answer by Jeff SandersMicrosoft employee, Moderator Thursday, December 1, 2011 1:25 PM
Wednesday, November 30, 2011 2:47 PMModerator
All replies
-
Hi - I have forwarded this question to our internal resources. I will update you when I know more or someone will answer this directly.
Matt Small - Microsoft Escalation Engineer - Forum ModeratorTuesday, September 27, 2011 2:23 PMModerator -
@ACarter - can you provide more details?
Creating RDs - we don't have an item template in the BUILD bits, but you can just add an XML file (as a .xaml file) and change the contents. Root would be:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <!-- your styles and templates --> </ResourceDictionary>
Then when you use it in your App.xaml (or other merged dictionary location), just make sure *not* to put in a leading slash in the Source (known issue).
Tim Heuer | Program Manager, XAML | http://timheuer.com/blog | @timheuer- Proposed as answer by Tim HeuerMicrosoft employee Tuesday, September 27, 2011 4:38 PM
- Unproposed as answer by A.Carter Tuesday, September 27, 2011 8:44 PM
Tuesday, September 27, 2011 4:33 PM -
Hey Tim,
I have been doing like you described (using the xml itemtemplate). I think i just found out what the problem is but i'm still unsure how to fix it.
In WPF i have a project set up like below:
WPF Solution
- Core Project
- Resources
- Brushes.xaml
- Fonts.xaml
- ButtonStyles.xaml
In ButtonStyles.xaml i am referencing a few resources from Fonts.xaml and Brushes.xaml. Also, in ButtonStyles.xaml i do not have Fonts.xaml or Brushes.xaml in my MergedDictionaries.
In my App.xaml i have merged the dictionaries like below:
<ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="/Resources/Brushes.xaml" /> <ResourceDictionary Source="/Resources/Fonts.xaml" /> <ResourceDictionary Source="/Resources/ButtonStyles.xaml" /> </ResourceDictionary.MergedDictionaries> </ResourceDictionary>
This allows the ButtonStyles.xaml to reference the resources from Brushes.xaml and Fonts.xaml.When i duplicate this structure in the metro project it seems like the ButtonStyles.xaml isn't able to find the resources in Brushes.xaml and Fonts.xaml. Everything does work when i add Brushes.xaml and Fonts.xaml to the MergedDictionaries of my ButtonStyles.xaml. My concern with this is that i would need to add the same resources to each ControlStyles.xaml (like TextBlockStyles.xaml, ComboBoxStyles.xaml, etc). Also, wouldn't that create the same Brush resources and Font resources?
Also, If there is an issue loading a ResourceDictionary that's located in App.xaml then i get greeted with a generic Message box stating "Unable to Activate Windows Tailored Application".
If i move those resources to my MainPage's MergedDictionaries then i get a little more information:
An exception of type 'Windows.UI.Xaml.Markup.XamlParseException' occurred in myApp.exe but was not handled in user code
Additional information: Failed to assign to property '%0'. [Line: 12 Position: 44]
But the error is still vague as i don't have a property named '%0'.
Hopefully, i didn't confuse the situation. I can send a repro project (the wpf and metro) if you're interested.
Tuesday, September 27, 2011 9:11 PM -
In your app xaml change to
<ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="Resources/Brushes.xaml" /> <ResourceDictionary Source="Resources/Fonts.xaml" /> <ResourceDictionary Source="Resources/ButtonStyles.xaml" /> </ResourceDictionary.MergedDictionaries> </ResourceDictionary>
Notice the removal of the leading slash. This was the known issue I mentioned above.
Tim Heuer | Program Manager, XAML | http://timheuer.com/blog | @timheuerTuesday, September 27, 2011 9:39 PM -
Yeah, i have done that (i was trying to describe the wpf project setup).
I don't think you are fully understanding what I am saying. I give - thanks anyway.
Tuesday, September 27, 2011 10:08 PM -
The code you pasted had leading slashes: "/Resources/Brushes.xaml" -- are you saying you REMOVED the leading slash and still seeing that? If so, there is likely an issue in one of your styles...
Tim Heuer | Program Manager, XAML | http://timheuer.com/blog | @timheuerTuesday, September 27, 2011 11:19 PM -
Did you solve your problem? Can you send me the project if you did not solve it?
Jeff Sanders (MSFT)- Proposed as answer by Jeff SandersMicrosoft employee, Moderator Wednesday, October 19, 2011 12:39 PM
- Marked as answer by Matt SmallMicrosoft employee, Moderator Friday, October 21, 2011 6:23 PM
- Unmarked as answer by Jeff SandersMicrosoft employee, Moderator Monday, November 14, 2011 12:43 PM
- Unproposed as answer by Jeff SandersMicrosoft employee, Moderator Monday, November 14, 2011 12:44 PM
Friday, October 14, 2011 12:41 PMModerator -
Hi Tim
i have generic.xaml inside themes folder in my project
now i tried to add it to resource dictionary by code as follows
ResourceDictionary dic1 = new ResourceDictionary
();
//dic1.Source = new Uri("/Test;component/Themes/generic.xaml", UriKind.Relative);
dic1.Source =
new Uri("ms-resource:Themes/generic.xaml", UriKind.Relative);
i tried the upper two lines but the 'System.UriFormatException' thrown in both
may i have error in my uri ?
Monday, November 14, 2011 6:56 AM -
Hi Shaker,
Check out this thread. It uses BaseUri as part of the solution:
-Jeff
Jeff Sanders (MSFT)- Proposed as answer by Jeff SandersMicrosoft employee, Moderator Wednesday, November 30, 2011 2:47 PM
- Marked as answer by Jeff SandersMicrosoft employee, Moderator Thursday, December 1, 2011 1:25 PM
Wednesday, November 30, 2011 2:47 PMModerator -
thanks jpsanders
it works fine
Thursday, December 1, 2011 6:13 AM