문제

I'm writing a library of WPF user controls and am having trouble with a resource image that I'm trying to access via some XAML. Just for fun, the image displays as expected at design time and only fails at run time.

I've tried setting the build action to "none", "content", "resource" and "embedded resource", but I keep getting the following cryptic exception:

'Provide value on 'System.Windows.Baml2006.TypeConverterMarkupExtension' threw an exception.' Line number '18' and line position '6'.

Looking at the inner exception, it seems to be a problem with the pack URI. When I try:

<ImageBrush x:Key="mybrush" ImageSource="pack://application:,,,/Resources/an image.png" />

I get:

Assembly.GetEntryAssembly() returns null.

OK, so this is probably because my library is now being called from within another assembly. But when I follow the recommendations and try:

<ImageBrush x:Key="mybrush" ImageSource="pack://application:,,,my_assembly;component;/Resources/an image.png" />

I get an inner exception of:

"The URI prefix is not recognized."

To add to the fun, I have another image resource which I have no problem accessing via actual C# code (i.e. not through XAML).

What am I doing wrong? Feel like it will be really simple, but am head-desking at the moment.

도움이 되었습니까?

해결책

Change ImageSource to

ImageSource="pack://application:,,,/my_assembly;component/Resources/your_image.p‌​ng"
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top