Solved

How can I add an enter to a ResourceDictionary element?

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

705 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

20 Experts available now in Live!

Get 1:1 Help Now