This question already has answers here:
In my WPF application, my loaded PNG logo in image shows at design time but not at run time
(4 answers)
Closed 7 years ago.
How to use resource image in WPF image source.I given like below,
<Image Source="pack://siteoforigin:,,,/Resources/008.jpg"/>.
But it displays in edit page.If i run the application it not displaying in the window.
Please help me to solve this.
Thanks.
you need to provide the correct URI to the resource, and the URI depends on the method you used to add the resource this post give the details you need
How to Embed resources
You can add your image to your project Properties.Resources.Images and then use them like that:
<Image Source="{x:Static Properties:Resources.YourImageName}"/>
EDIT >>>>
I've forgotten to say that you have to add this line at the top:
<xmlns:Properties="clr-namespace:yournamespace.Properties"/>
Related
This question already has answers here:
WPF - Import image as resource
(3 answers)
Closed 7 years ago.
I'm using VS2013. .NetFramework 3 . I'm writing a simple project like as image gallery.
I'm trying to add an JPEG image into Image Control. First I'm adding the test.jpg image as resource. Then I'm adding an Image Control on to Window. In the next step I'm selecting the image in "Source" property. The image displaying into design mode. All is ok. But when I'm running the project nothing displaying.
I searched in google and youtube. I founded some solutions but I haven't solution for my problem
(Sorry for ENG)
Here the code line
<Image Source="pack://siteoforigin:,,,/Resources/1.JPG" ... />
In order to simply display the image in WPF app, do the following:
1). In XAML, add:
<Image Name="imgName" Source="/ProjAssemblyName;component/RelativePathToImageFile" />
2). In Visual Studio IDE, select the image file and check its properties:
Build Action: Resources
Copy to Output Directory: Do Not Copy
Note: in most typical case the project Assembly name is the same as Default Namespace; check it in application property dialog. Also useful info pertinent to your case is included in the Microsoft reference (as pointed out by member #Clemens): https://msdn.microsoft.com/en-us/library/aa970069%28v=vs.110%29.aspx#Resource_File_Pack_URIs___Local_Assembly.).
Another option is to set the image Build Action property to EmbeddedResource and get the BitmapImage object corresponding to the image file programmatically like the following:
BitmapImage _bmpImage = new BitmapImage();
_bmpImage.BeginInit();
_bmpImage.StreamSource = Assembly.GetExecutingAssembly().GetManifestResourceStream(String.Concat(ProjAssemblyName, ImgFile));
_bmpImage.EndInit();
This technique is useful if further image processing is considered.
Hope this may help. Kind regards,
This question already has answers here:
Load a ResourceDictionary from an assembly
(3 answers)
Closed 8 years ago.
I'm having some issues. I want my app to load a ResourceDictonnary dynamically in app.xaml.cs.
This is my code for the moment :
ResourceDictionary theme = XamlReader.Load(???);
Resources.MergedDictionaries.Add(theme);
The problem is, how can I get my ResourceDictionnary stream from the xaml file ? I don't want to copy the xaml file with the exe. It's build action is set to Page and I want to load it.
Can you tell me how to do that ?
Thanks !
try using the following code (I call it from my IModule.Initialize)
Application.Current.Resources.MergedDictionaries
.Add(new ResourceDictionary
{
Source = new Uri(#"pack://application:,,,/My.Application;component/Resources/Resources.xaml")
});
see the project tree in attached image:
This question already has answers here:
Programmatically close aspx page from code behind
(13 answers)
Closed 9 years ago.
I am Unable to close current asp.net page using C# code. I tried:
ClientScript.RegisterClientScriptBlock(Page.GetType(),
"script",
"window.close();",
true);
I am not getting any error, but it doesn't work.
Try the following link
Programmatically close aspx page from code behind
Based on the scenario it may very. Please read the above thread replies
Also the following link shows the same question
How to close the current tab in the server side button click?
Try this
ClientScript.RegisterStartupScript(typeof(Page),
"closePage",
"window.close();",
true);
I have a small C# project that has an ApplicationBar. But I have a small problem: I want 8 icons on the bar, and the ApplicationBar only supports 4. I came up with a solution (in C#): add a small CheckBox to ask if the user wants to use the first or second set of tools.But I'm still not able to change the icons on the ApplicationBar. I tried removing the old ones, first with ApplicationBar.MenuItems.Remove(Button1); and then with ApplicationBar.Buttons.Remove(Button1);
but neither worked. I tried changing the .IconUri property of the button, but that gave me a NullReferenceException.
I don't understand what you mean by changing it from "C#, not Silverlight". C# is a programming language and Silverlight is a framework. Nevertheless, the link you posted to explains exactly how you do it. The ApplicationBar is not a Silverlight control, it's part of the native OS. You can use the code in the link or do something like this:
firstAppBarButton = (ApplicationBarIconButton)ApplicationBar.Buttons[0];
firstAppBarButton.Text = "New Text";
firstAppBarButton.IconUri = new Uri("/appbarIcon.png",UriKind.Relative);
You need to get the ApplicationBarIconButton via the index (0 for first one, 1 for second etc..) instead of by name.
You can't refer to the application buttons by name. Try:
((ApplicationBarIconButton)ApplicationBar.Buttons[0]).Remove
I would also suggest that you do not present two groups of 4 icons to the user. The limit is 4 for a reason. Any more than that requires a UI re-think. Perhaps divide the functionality over a few pages?
The syntax above gave me a compile error. With some additional research, I got this to work for me:
ApplicationBar.Buttons.Remove((ApplicationBarIconButton) ApplicationBar.Buttons[0]);
I have a small C# project that has an ApplicationBar. But I have a small problem: I want 8 icons on the bar, and the ApplicationBar only supports 4. I came up with a solution (in C#): add a small CheckBox to ask if the user wants to use the first or second set of tools.But I'm still not able to change the icons on the ApplicationBar. I tried removing the old ones, first with ApplicationBar.MenuItems.Remove(Button1); and then with ApplicationBar.Buttons.Remove(Button1);
but neither worked. I tried changing the .IconUri property of the button, but that gave me a NullReferenceException.
I don't understand what you mean by changing it from "C#, not Silverlight". C# is a programming language and Silverlight is a framework. Nevertheless, the link you posted to explains exactly how you do it. The ApplicationBar is not a Silverlight control, it's part of the native OS. You can use the code in the link or do something like this:
firstAppBarButton = (ApplicationBarIconButton)ApplicationBar.Buttons[0];
firstAppBarButton.Text = "New Text";
firstAppBarButton.IconUri = new Uri("/appbarIcon.png",UriKind.Relative);
You need to get the ApplicationBarIconButton via the index (0 for first one, 1 for second etc..) instead of by name.
You can't refer to the application buttons by name. Try:
((ApplicationBarIconButton)ApplicationBar.Buttons[0]).Remove
I would also suggest that you do not present two groups of 4 icons to the user. The limit is 4 for a reason. Any more than that requires a UI re-think. Perhaps divide the functionality over a few pages?
The syntax above gave me a compile error. With some additional research, I got this to work for me:
ApplicationBar.Buttons.Remove((ApplicationBarIconButton) ApplicationBar.Buttons[0]);