How change the desktop shortcut image of WPF application? - wpf

I am creating a WPF Application, and I wanted to publish it. So I created a new Setup and Deployment project, and added my application to it. Now, when I created the setup file and ran it...it created a desktop shortcut. But the image on the desktop shortcut was a windows default, and I want to change it to another icon file. Please tell me how to do that.
Thanks.

First, you will need to add an icon to your project. In the properties of your icon, set Build Action to Resource.
Then, in your main Window.xaml file, set the Icon property.
<Window x:Class="..."
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
**Icon="YourIcon.ico"**>

And also you can add an .ico file to user's program files folder. After that you can add the shourtcut to user's desktop. Important point is you should configure the shourtcut's target to that .ico folder.
I hope this helps

Open Properties window of application. In Application section there is "Icon and manifest". Add icon there. More details is here

Related

icon in task bar will not change when winform is published

I have a winform app running on .net 4. When a certain condition happens, the icon running in the task bar changes from ping_logo to ping_logo_red. (the icon i'm talking about is the one that shows up when you run an application. You click on it and it will restore the windows to the screen or minimize it) The way that the icon is changing is as follows.
I added the ico files as Resources. In the code I change the resource being used
Me.Icon = My.Resources.ping_logo_red
Here is the thing. This works when I run the exe from my machine from the solution bin/release folder. When I publish this and install it from the published location, the icon does not change.
In the publish tab under the project both ping_logo.ico and ping_logo_red.ico are included in the publish status.
what have I not done that is keeping the icon from working in the published app. I've tried to uninstall the app and install it fresh but that doesn't seem to make a difference.
thanks
shannon
If you are using ClickOnce to publish your application then you need to set the icon property in the properties window of your project.
Right click your project -> Properties
Go to application tab
Select your icon file towards the bottom.
Another idea is changing the CopyToOutput property of your .ico file to "Copy Always" or "Copy If Newer".

how to set startup uri property to another window in folder in wpf project

In my wpf project i have created a folder called practice, in that folder i added a window, now i want to run that window, so in app.xaml file i set the startup uri to foldername.window.xaml but it is saying build action property is not set to resource.
for that i setted build action property to resource. Now this time that it is showing error message initialized componenet doesn't exist in the current context.
Can you tell me what properties we need to set when we create separate folders in wpf project and that folders contains windows or pages. and How to access those pages in other pages or in App.Xaml file startupUri Property.
When you have folders in your project structure, you should use a "/" not a ".", so it's foldername/window.xaml.
(I hope it's not actually called window.xaml by the way. That's a confusing name for a type in a WPF project, because there's a built in type called Window.)
Setting the build action to Resource will make matters worse: not only were you using the wrong name, you've now changed the build action to the wrong one for XAML. The correct build action for a .xaml file is usually Page. (App.xaml is an exception to that rule.) The Page build action causes the page to be compiled into a binary representation (known as BAML), and that binary format can then be loaded either by the call to InitializeComponent in the codebehind, or through Application.LoadComponent.
Setting the build action to Resource will just embed a copy of the XAML source directly in the project, which won't help you - you can't work with XAML in that form if you want to have a codebehind file. (Not in WPF, anyway. It's different in other XAML-based frameworks such as WinRT.)
Since Page is the default build action for a newly-added window, you don't actually need to set any properties at all. You just need to use / for folder boundaries.
If the XAML is inside any Folder the startup url will be defined as below.
This is how it will defined.

WPF doesn't load images correctly

I have some icons in my WPF project to make the application more user friendly. WPF shows all icons on my computer but when I run the app on other computers it will show some of icons but not all of them. How can I fix it?
Update:
<Image Source="Office/Add-Female-User.ico" Stretch="None" />
I'm sure that all images are accessible because some of them are visible.
You are referencing your images (in your image controls) as Content not Resource. I suspect the problem is your images aren't copied to the output dir. View properties on missing image files and set build action to Content and Copy to output dir to Copy if newer.
For resource referencing see http://msdn.microsoft.com/en-us/library/aa970069.aspx.

Loading a application inside another one

I would like my application WPF can load a ".exe" file and show it inside itself. I have my main WPF that checks a folder where it load plugins with MEF, but I only can load "dll" files without UI. So I found x plugins, I can load informations and in the same way I want to open a UI associate with the dll loaded.
I don't know if it's understandable what I want to do but if you have an idea that can help me, I take it.
In a dll you can add UI elements.
Add for example a Window to your plugin project (project with dll output) and use the following code when you create an instance of your plugin in your main application:
Window win = new Window();
win.Show();

How to make .exe file programmatically set to run as admin always in vista?

I have written a winform application in C#. When I run the program for some functionality it required admin permission. After Installation If I set the .exe file to run as admin manually (by clicking right mouse button on .exe file) then my program run perfectly.
Now I need user not to set the run as admin property after installation by clicking right mouse button. I need to set this programaticaly somewhere in the code that user no need to bother about this. This specific problem is only arise for Windows Vista. Can anyone help me out?
You need to add a manifest to the app that specifies it require admin privileges. Read more on MSDN.
Update: You can add a manifest to your project by right-clicking on the project and selecting Add / New Item / Application Manifest File. This will add a new file called app.manifest to your project and will reference it from the project properties, in the Manifest dropdown on the Application tab. The default manifest template even has a nice comments on how exactly to change the required UAC execution level.
You need to specify the requestedExecutionLevel in the manifest.
See here for a detailed explanation:
http://petesbloggerama.blogspot.com/2007/04/making-your-assembly-run-as.html

Resources