pack-uri

How can I access a resource image within XAML in a user control library?

两盒软妹~` 提交于 2019-12-11 12:22:58
问题 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'.

At design time pack uri is valid, but not at runtime?

孤街醉人 提交于 2019-12-09 15:37:45
问题 I'm setting a Button's content to an Image. It looks something like this: <Button> <Image Source="pack://application:,,,/NavigationImages/nav_up_left.png" /> </Button> In my project I have a subfolder named NavigationImages and within that folder is the image file nav_up_left.png. When I view the Designer the image appears, however during runtime I get an IOException error saying it cannot locate the resource. The Build Action is set to Resource. Actually, this worked fine in one project. But

At design time pack uri is valid, but not at runtime?

与世无争的帅哥 提交于 2019-12-05 19:26:12
问题 I'm setting a Button's content to an Image. It looks something like this: <Button> <Image Source="pack://application:,,,/NavigationImages/nav_up_left.png" /> </Button> In my project I have a subfolder named NavigationImages and within that folder is the image file nav_up_left.png. When I view the Designer the image appears, however during runtime I get an IOException error saying it cannot locate the resource. The Build Action is set to Resource. Actually, this worked fine in one project. But

Detect whether WPF resource exists, based on URI

我怕爱的太早我们不能终老 提交于 2019-12-04 10:21:03
问题 Given a pack:// URI, what's the best way to tell whether a compiled resource (e.g. a PNG image, compiled with a Build Action of "Resource") actually exists at that URI? After some stumbling around, I came up with this code, which works but is clumsy: private static bool CanLoadResource(Uri uri) { try { Application.GetResourceStream(uri); return true; } catch (IOException) { return false; } } (Note that the Application.GetResources documentation is wrong -- it throws an exception if the

At design time pack uri is valid, but not at runtime?

那年仲夏 提交于 2019-12-04 02:33:57
I'm setting a Button's content to an Image. It looks something like this: <Button> <Image Source="pack://application:,,,/NavigationImages/nav_up_left.png" /> </Button> In my project I have a subfolder named NavigationImages and within that folder is the image file nav_up_left.png. When I view the Designer the image appears, however during runtime I get an IOException error saying it cannot locate the resource. The Build Action is set to Resource. Actually, this worked fine in one project. But when I copied it over the another project it fails. This seems like an incredibly simple problem, but

Detect whether WPF resource exists, based on URI

强颜欢笑 提交于 2019-12-03 05:40:54
Given a pack:// URI, what's the best way to tell whether a compiled resource (e.g. a PNG image, compiled with a Build Action of "Resource") actually exists at that URI? After some stumbling around, I came up with this code, which works but is clumsy: private static bool CanLoadResource(Uri uri) { try { Application.GetResourceStream(uri); return true; } catch (IOException) { return false; } } (Note that the Application.GetResources documentation is wrong -- it throws an exception if the resource isn't found, rather than returning null like the docs incorrectly state.) (The docs have been

Pack URI and path not resolving image in WPF

给你一囗甜甜゛ 提交于 2019-12-01 05:42:10
问题 I have the following directory structure Project \Images +view.png control.xaml and in the control I have a button defined by the following XAML: <Button Click="Search" Grid.Column="1" Margin="0,5,5, 0" HorizontalAlignment="Right"> <Button.Template> <ControlTemplate TargetType="{x:Type Button}"> <Image Source="pack://application:,,,/images/view.png" Width="16" Height="16" ToolTip="Search" Cursor="Hand" Opacity="0.8" /> </ControlTemplate> </Button.Template> </Button> However, neither this pack

Avoiding Visual Studio designer errors when WPF resource is defined in separate project

梦想的初衷 提交于 2019-11-28 06:45:58
How can I avoid Visual Studio designer errors when a WPF resource is defined in separate project? I have three projects in a composite WPF application: the main application, an "infrastructure" library, and a "module" library. The main application references the other projects via their output DLLs (the projects are not located in a single solution together). I am defining a skin (some brushes and styles in a ResourceDictionary ) in the "infrastructure" library. I would like the main application to select a skin and make it available to the entire application (via MergedDictionaries in App

How can I get a BitmapImage from a Resource?

江枫思渺然 提交于 2019-11-28 06:45:37
My assembly includes an image with BuildAction==Resource. I want to obtain a BitmapImage from this embedded resource. I can load a BitmapImage from file like this: var bitmap = new BitmapImage(new Uri(path)); But how to I create a Uri that will refer to an embedded resource image? When I try and create a ' pack URI ' (for example pack://application:,,,/MyImage.png or pack://application:,,,/MyAssembly;component/MyImage.png ), an exception is thrown: System.UriFormatException "Invalid URI: A port was expected because of there is a colon (':') present but the port could not be parsed." I found

How can I get a BitmapImage from a Resource?

本秂侑毒 提交于 2019-11-27 05:41:41
问题 My assembly includes an image with BuildAction==Resource. I want to obtain a BitmapImage from this embedded resource. I can load a BitmapImage from file like this: var bitmap = new BitmapImage(new Uri(path)); But how to I create a Uri that will refer to an embedded resource image? When I try and create a 'pack URI' (for example pack://application:,,,/MyImage.png or pack://application:,,,/MyAssembly;component/MyImage.png ), an exception is thrown: System.UriFormatException "Invalid URI: A port