[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework

Multi-line strings in ResourceDictionary.xaml

Kirill

10/28/2008 11:33:00 PM

Hello,

For those, who read this newsgroup via the browser: I'm sorry about the
repost, but the post does not appear to be on the newsgroup server, and that
could be a reason that I've not received *any* replies.

How do I specify a string with line breaks in a resource dictionary?

Here is what I want:
I'd like to put a string that contains line breaks (or other special
entities), e.g. 
 or \n, into a resource dictionary. In other words, I'd
like my resouce dictionary to look like:

<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presenta...
xmlns:x="http://schemas.microsoft.com/winfx/2006/...
xmlns:System="clr-namespace:System;assembly=mscorlib"
<System:String x:Key="TwoLiner">First line&#10;Second line</System:String>
</ResourceDictionary>


Here is the problem:
when I retrieve that string with

ResourceDictionary _main = (ResourceDictionary)Application.LoadComponent(new
Uri("WpfCustomControlLibrary2;;;component/CustomDictionary.xaml",
UriKind.Relative));
string twoLiner = _main["TwoLiner"] as string;

the line break (&#10; in .xaml) is replaced with ' ' (\32 in C#)


Here is what I found:
- I tried to use a workaround to a similar problem described in
http://social.msdn.microsoft.com/forums/en-US/wpf/thread/621b9169-94d0-4217-808d-e3a...
but I could not make it work and always received internal compiler error
'Object reference not set to an instance of an object.' unless I used
attribute syntax like

<src:ResourceString x:Key="TwoLiner" Value="First line&#10;Second line" />

- to solve the internal compiler error, I tried to write a TypeConverter
that can convert from string to ResourceString, but the error still appears.


Although it's somewhat working, I'd like to:
- either use System:String;
- or use ResourceString but specify the string in the dictionary in the
usual - content - way (not as an attribute).

Thank you for any help or ideas!

Kirill.


5 Answers

v-mazho

10/29/2008 9:30:00 AM

0

Hello Kirill,

Welcome to Microsoft Newsgroup Support Service! My name is Marco Zhou. It's
my pleasure to work with you on this thread.

If I understand your question correctly, you need to define pure
System.String resource in XAML, if this is the case, you could try
something like the following snippet:

<Window.Resources>
<System:String x:Key="TwoLiner" xml:space="preserve">First
line&#10;Second line</System:String>
</Window.Resources>

The xml:space attribute here means that we want to preserve the white space
when parsing, and "&#10;" XML entity means "\n"(aka newline character).

For more information on whitespace handling in XAML, please refer to the
following article:
http://msdn.microsoft.com/en-us/library/ms7...

If you have any further questions on this issue, free feel to ask here, we
are glad to answer them.

--------------------------------------------------
Best regards,
Macro Zhou (v-mazho@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no rights.

Kirill

10/29/2008 1:37:00 PM

0

Marco,

you wrote:
> If I understand your question correctly, you need to define pure
> System.String resource in XAML,
Yes, that's exactly what I wanted to do. The trick is I wanted to have line
breaks (aka \n, aka &#10;) within those pure strings.

> if this is the case, you could try something like the following snippet:
>
> <Window.Resources>
> <System:String x:Key="TwoLiner" xml:space="preserve">First
> line&#10;Second line</System:String>
> </Window.Resources>
>
> The xml:space attribute here means that we want to preserve the white
> space
> when parsing, and "&#10;" XML entity means "\n"(aka newline character).
>
> For more information on whitespace handling in XAML, please refer to the
> following article:
> http://msdn.microsoft.com/en-us/library/ms7...
Thank you so much! You managed to remove a lot of code that you haven't even
seen :)

--
Kirill.

Ashutosh Bhawasinka

10/30/2008 4:01:00 AM

0

Apart from that...if you are using the Resource editor (in the IDE) you
can first type your multi-line text in application like notepad then
copy and paste it in the resource editor....Thats how I do!!!

Thanks & Regards,
Ashutosh Bhawasinka

Kirill wrote:
> Hello,
>
> For those, who read this newsgroup via the browser: I'm sorry about the
> repost, but the post does not appear to be on the newsgroup server, and that
> could be a reason that I've not received *any* replies.
>
> How do I specify a string with line breaks in a resource dictionary?
>
> Here is what I want:
> I'd like to put a string that contains line breaks (or other special
> entities), e.g. &#10; or \n, into a resource dictionary. In other words, I'd
> like my resouce dictionary to look like:
>
> <ResourceDictionary
> xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presenta...
> xmlns:x="http://schemas.microsoft.com/winfx/2006/...
> xmlns:System="clr-namespace:System;assembly=mscorlib"
> <System:String x:Key="TwoLiner">First line&#10;Second line</System:String>
> </ResourceDictionary>
>
>
> Here is the problem:
> when I retrieve that string with
>
> ResourceDictionary _main = (ResourceDictionary)Application.LoadComponent(new
> Uri("WpfCustomControlLibrary2;;;component/CustomDictionary.xaml",
> UriKind.Relative));
> string twoLiner = _main["TwoLiner"] as string;
>
> the line break (&#10; in .xaml) is replaced with ' ' (\32 in C#)
>
>
> Here is what I found:
> - I tried to use a workaround to a similar problem described in
> http://social.msdn.microsoft.com/forums/en-US/wpf/thread/621b9169-94d0-4217-808d-e3a...
> but I could not make it work and always received internal compiler error
> 'Object reference not set to an instance of an object.' unless I used
> attribute syntax like
>
> <src:ResourceString x:Key="TwoLiner" Value="First line&#10;Second line" />
>
> - to solve the internal compiler error, I tried to write a TypeConverter
> that can convert from string to ResourceString, but the error still appears.
>
>
> Although it's somewhat working, I'd like to:
> - either use System:String;
> - or use ResourceString but specify the string in the dictionary in the
> usual - content - way (not as an attribute).
>
> Thank you for any help or ideas!
>
> Kirill.
>
>
>

Kirill

10/30/2008 1:50:00 PM

0

Ashutosh Bhawasinka,

you wrote:
> Apart from that...if you are using the Resource editor (in the IDE) you
> can first type your multi-line text in application like notepad then copy
> and paste it in the resource editor....Thats how I do!!!
Unfortunately, we can't use Resource editor, because it edits .resx files,
not .xaml files. But if one uses Resource editor (and .resx files), then
your hint is wonderful!

Kirill.

> Kirill wrote:
>> Hello,
>>
>> For those, who read this newsgroup via the browser: I'm sorry about the
>> repost, but the post does not appear to be on the newsgroup server, and
>> that could be a reason that I've not received *any* replies.
>>
>> How do I specify a string with line breaks in a resource dictionary?
>>
>> Here is what I want:
>> I'd like to put a string that contains line breaks (or other special
>> entities), e.g. &#10; or \n, into a resource dictionary. In other words,
>> I'd
>> like my resouce dictionary to look like:
>>
>> <ResourceDictionary
>> xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presenta...
>> xmlns:x="http://schemas.microsoft.com/winfx/2006/...
>> xmlns:System="clr-namespace:System;assembly=mscorlib"
>> <System:String x:Key="TwoLiner">First line&#10;Second
>> line</System:String>
>> </ResourceDictionary>

Ashutosh Bhawasinka

10/31/2008 11:39:00 AM

0

Yes, you are correct!!! thats why added the phrase "Apart from that" at
the beginning of my sentence :)

Kirill wrote:
> Ashutosh Bhawasinka,
>
> you wrote:
>> Apart from that...if you are using the Resource editor (in the IDE)
>> you can first type your multi-line text in application like notepad
>> then copy and paste it in the resource editor....Thats how I do!!!
> Unfortunately, we can't use Resource editor, because it edits .resx
> files, not .xaml files. But if one uses Resource editor (and .resx
> files), then your hint is wonderful!
>
> Kirill.
>
>> Kirill wrote:
>>> Hello,
>>>
>>> For those, who read this newsgroup via the browser: I'm sorry about
>>> the repost, but the post does not appear to be on the newsgroup
>>> server, and that could be a reason that I've not received *any*
>>> replies.
>>>
>>> How do I specify a string with line breaks in a resource dictionary?
>>>
>>> Here is what I want:
>>> I'd like to put a string that contains line breaks (or other special
>>> entities), e.g. &#10; or \n, into a resource dictionary. In other
>>> words, I'd
>>> like my resouce dictionary to look like:
>>>
>>> <ResourceDictionary
>>> xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presenta...
>>> xmlns:x="http://schemas.microsoft.com/winfx/2006/...
>>> xmlns:System="clr-namespace:System;assembly=mscorlib"
>>> <System:String x:Key="TwoLiner">First line&#10;Second
>>> line</System:String>
>>> </ResourceDictionary>
>