Solved

How can I add an enter to a ResourceDictionary element?

Posted on 2013-06-28
3
421 Views
Last Modified: 2013-06-28
Dear Experts-Exchange:

I am attempting to include an enter into a ResourceDictionary element (Example: x:Key="CustomerName").  Bellow you will find a snipet of the ResourceDictionary I refer to:

<ResourceDictionary 
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
	xmlns:system="clr-namespace:System;assembly=mscorlib">

	<system:String x:Key="CustomerName">Customer 
Name</system:String>
</ResourceDictionary>

Open in new window


I will appreciate your reply.

Best regards,

Conrado
0
Comment
Question by:Conrado ZAVALA
  • 2
3 Comments
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 250 total points
ID: 39285670
As most XML parser, by default the XAML parser skip white space (space, carriage returns, line feeds). You need to tell the parser that you want to keep the carriage return in your string, and then use the standard xml escape code for a carriage return:

<system:String x:Key="CustomerName" xml:space="preserve">Customer&#10;Name</system:String>

Open in new window

0
 

Author Closing Comment

by:Conrado ZAVALA
ID: 39285728
Hello James.  You have no idea about how much this solution mean to me.  Thank you very much (honestly).

Best regard,

Conrado
0
 
LVL 40
ID: 39285807
It also means to me.

My main type of development is done with Windows Application projects, and the resource files they use, although they are also in xml, are a lot easier to use when you need a carriage return inside of a string value.

I am just learning to program Windows Store applications, so the ResourceDictionary is something I am just beginning to use. I started answering your question thinking that it would be as easy as in a Windows Application, where a simple Shift-Enter in the resource file does the trick. When I tried in in a ResourceDictionary, it did not work.

I had some free time, so I went out to find the solution. As is almost always the case with those things, finding the solution is a nightmare. You always find 20 different ways to do the thing... and none of them works. The fact that Silverlight, WPF and Windows Store projects use basically the same concepts but with little annoying differences is a nightmare.

I finally was able to make the thing work in my environment by combining 2 different solutions that were supposed to work separately but did not until they were combined.

I learned something that will be useful to me in the future. So, thanks for your question.
0

Featured Post

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question