Solved

How can I add an enter to a ResourceDictionary element?

Posted on 2013-06-28
3
419 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

813 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now