开发者

WPF - Return image from converter using pack URI

I would like to create a WPF converter to return a ce开发者_如何转开发rtain image depending on a boolean value.

I have so far got the following code:

 return (bool) value
                   ? new BitmapImage(new Uri("pack://application:,,,MyApp.ApplicationResources;component/Resources/image1.png", UriKind.Absolute))
                   : new BitmapImage(new Uri("pack://application:,,,MyApp.ApplicationResources;component/Resources/image2.png", UriKind.Absolute));

However this gives me the exception

System.Windows.Markup.XamlParseException occurred 
Message=The URI prefix is not recognized.

The Images are in a referenced Assembly of : MyApp.ApplicationResources in a folder "Resources" and both are set to Content Type: Resource.

If I use the same URI in source property of an image in xaml it works fine!

Any ideas? Thanks


Looks like you are missing a / in your Uri:

return (bool) value
               ? new BitmapImage(new Uri("pack://application:,,,/MyApp.ApplicationResources;component/Resources/image1.png", UriKind.Absolute))
               : new BitmapImage(new Uri("pack://application:,,,/MyApp.ApplicationResources;component/Resources/image2.png", UriKind.Absolute));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜