I am trying to create a reusable System:Char
value in my xaml
resources.
I have:
xmlns:s="clr-namespace:System;assembly=mscorlib"
Then:
<s:Char x:Key="MaskPromptChar">#</s:Char>
I get an exception:
The type 'Char' was not found. [Line: 8 Position: 44]
But... I also have:
<s:Double x:Key="DefaultControlWidth">200</s:Double>
And...
<s:String x:Key="ApplicationTitle">My Title</s:St开发者_JS百科ring>
Both String
and Double
work fine.
Ideas??
This code works for me in both Silverlight and WPF.
<UserControl.Resources>
<sys:Double x:Key='myDouble'>4</sys:Double>
<sys:Char x:Key='myChar'>#</sys:Char>
</UserControl.Resources>
<StackPanel x:Name="LayoutRoot">
<PasswordBox Password='aaa'
PasswordChar='$' />
<PasswordBox Password='aaa'
PasswordChar='{StaticResource myChar}' />
</StackPanel>
What property are you trying to assign the char to?
My guess is that Char is a structure, rather than an object, and what's you're really looking at is boxing of a 16-bit integer value representing Unicode. I tend to look at XAML as a specialization serialization of objects, and if Char is actually a struct, this model may break down.
You might want to consider biting the bullet and using a String of length one instead.
UPDATE: I agree with gmcalab's solid line of reasoning, and based on that conducted an experiment using a namespace to mscorlib and the corresponding character resource. It worked without a hitch. (Are we now looking at a namespace or library collision problem?)
精彩评论