Friday, 15 March 2013

c# - In my WPF application, my loaded PNG logo in image shows at design time but not at run time -


It is probably something simple that I remember I have a PNG file that I have in my WPF window * Image * I want to use as a source of control. I have a project property & gt; Resources & gt; Add the existing file and first as a linked file (and then embedded when it was not working). Then I will add * source * to image control in XAML file. No code is included, simple click

The annoying problem is that when I'm designing the WPF window, the image shows when I run it, it doesnt. Nothing appears.

Update: Added XAMLL code

   below < Window x: orbit = "server.mainwindow" xmlns = "http://schemas.microsoft.com/enfx/ 2006/xaml/presentation" xmlns: x = "http://schemas.microsoft.com/winfx/2006/ Xaml "title =" server "height =" 467.91 "width =" 620.522 "& gt; & Lt; Grid & gt; & Lt; Grid.Background & gt; & Lt; LinearGradientBrush EndPoint = "0.5,1" Start Page = "0.5,0" & gt; & Lt; GradientStop color = "#FF080C59" offset = "0" /> & Lt; GradientStop color = "white" offset = "1" /> & Lt; / LinearGradientBrush & gt; & Lt; /Grid.Background> & Lt; Button x: name = "btn connect" content = "connect" horizontal alignment = "left" height = "30" margin = "425,34,0,0" workspaceElement = "top" width = "134" click = "BTN Connect-link "" /> button x: name = "btn disconnected" content = "disconnect" horizontal alignment = "left" height = "35" margin = "425,69,0,0" vertical alignment = "Top" width = "134" click = "BTN discconnect_list" />  button x: name = "btnandend" content = "send" horizontal alignment = "left" height = "35" margin = "425,120,0,0" wart Klelinement = "top" width = Click "134" = "Bitiansandji" / "& gt; & Lt; ListView x: name = "lsvClients" height = "67" margin = "46,212,260,0" vertical alignment = "top" & gt; & Lt; ListView.View & gt; & Lt; GridView & gt; & Lt; GridViewColumn / & gt; & Lt; / GridView & gt; & Lt; /ListView.View> & Lt; / ListView & gt; & Lt; Image horizontal alignment = "left" height = "100" margin = "31,10,0,0" vertical alignment = "top" width = "101" source = "pack: // cytoophorigin: ,,,, images / ServerMainLogo Png "/> & Lt; / Grid & gt; & Lt; / Window & gt;   

What am I missing? Thank you

When you specify image URI in XAML, then it is not usually necessary to write a full URI is. In addition to the full packed URI shown in the second reply, you should be able to write it:

  & lt; Image ... source = "picture / server_man .png" /> However, you have to make sure that the image file is located in your Visual Studio project folder called  images  and it's set to    

P>

Optionally you build action to content and copy output directory to always copy Or if copy is new . In this case the image has not been embedded as a resource in the assembly of the program, rather it is copied to any directory relative to the executable file.

In XAML (relative) image urr will work in both cases.

No comments:

Post a Comment