[英]Setting Icon for wpf application (VS 08)
Before going much further i'll mention I have tried solutions in following: 在进一步说明之前我会提到我在以下方面尝试了解决方案:
How do I set the icon for my application in visual studio 2008? 如何在visual studio 2008中为我的应用程序设置图标?
Set application icon from resources in VS 05 从VS 05中的资源设置应用程序图标
I am trying to set an icon for my application. 我正在尝试为我的应用程序设置一个图标。
AFAIK, I need potentially 3 images? AFAIK,我需要3张图片吗?
So thats fine. 那很好。
Now I have selected an Icon. 现在我选择了一个Icon。 How do I use it in one of above situations?
如何在上述情况之一中使用它?
I have tried adding it in resources, nothing seems to happen. 我尝试在资源中添加它,似乎没有任何事情发生。 Following that first SO solution,
在第一个SO解决方案之后,
"First go to Resource View (from menu: View --> Other Window --> Resource View). Then in Resource View navigate through resources, if any. If there is already a resource of Icon type, added by Visual Studio, then open and edit it. Otherwise right-click and select Add Resource, and then add a new icon." “首先进入资源视图(从菜单:查看 - >其他窗口 - >资源视图)。然后在资源视图中导航资源,如果有的话。如果已经有一个图标类型的资源,由Visual Studio添加,那么打开并编辑它。否则右键单击并选择Add Resource,然后添加一个新图标。“
The resource view is empty, and I cannot right click in this view. 资源视图为空,我无法右键单击此视图。
If I right click on the solution > properties > resources > I can add the icon image, but it doesn't show in either of the locations listed above. 如果我右键单击解决方案>属性>资源>我可以添加图标图像,但它不会显示在上面列出的任何位置。 (or anywhere that I can see)
(或我能看到的任何地方)
1) How do I set the application icon for a WPF Application? 1)如何为WPF应用程序设置应用程序图标?
Assuming you use VS Express and C#. 假设您使用VS Express和C#。 The icon is set in the project properties page.
该图标在项目属性页面中设置。 To open it right click on the project name in the solution explorer.
要打开它,请右键单击解决方案资源管理器中的项目名称。 in the page that opens, there is an Application tab, in this tab you can set the icon.
在打开的页面中,有一个“应用程序”选项卡,在此选项卡中可以设置图标。
@742's answer works pretty well, but as outlined in the comments when running from the VS debugger the generic icon is still shown. @ 742的答案非常有效,但正如在VS调试器中运行时的评论所述,仍会显示通用图标。
If you want to have your icon even when you're pressing F5, you can add in the Main Window: 如果您想在按F5时显示图标,可以在主窗口中添加:
<Window x:Class="myClass"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Icon="./Resources/Icon/myIcon.png">
where you indicate the path to your icon (the icon can be *.png
, *.ico
.) 在哪里指明图标的路径(图标可以是
*.png
, *.ico
。)
(Note you will still need to set the Application Icon or it'll still be the default in Explorer). (注意,您仍然需要设置应用程序图标,否则它仍然是资源管理器中的默认设置)。
Note: (replace file.ico with your actual icon filename) 注意:(将file.ico替换为您的实际图标文件名)
Icon=".\\file.ico"
on the Window Icon=".\\file.ico"
After getting a XamlParseException with message: 'Provide value on 'System.Windows.Baml2006.TypeConverterMarkupExtension' with the given solutions, setting the icon programmatically worked for me. 在获得带有消息的XamlParseException之后: '使用给定的解决方案为'System.Windows.Baml2006.TypeConverterMarkupExtension'提供值 ,以编程方式设置图标为我工作。 This is how I did it:
我就是这样做的:
Icon = new BitmapImage(new Uri("< icon_path >", UriKind.Relative)); Icon = new BitmapImage(new Uri(“< icon_path >”,UriKind.Relative));
Please inform me if you have any difficulties implementing this solution so I can help. 如果您在实施此解决方案时遇到任何困难,请通知我,以便我提供帮助。
You can try this also: 你也可以试试这个:
private void Page_Loaded_1(object sender, RoutedEventArgs e)
{
Uri iconUri = new Uri(@"C:\Apps\R&D\WPFNavigation\WPFNavigation\Images\airport.ico", UriKind.RelativeOrAbsolute);
(this.Parent as Window).Icon = BitmapFrame.Create(iconUri);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.