设置wpf应用程序的图标(VS 08)

发布于 2024-08-29 15:50:16 字数 937 浏览 4 评论 0原文

在进一步讨论之前,我会提到我已经尝试过以下解决方案:

如何在 Visual Studio 2008 中设置应用程序的图标?

从 VS 05 中的资源设置应用程序图标

我正在尝试为我的应用程序设置图标。

AFAIK,我可能需要 3 张图片?

  • 1 个图像是单击 .exe 时资源管理器中的实际图像(exe 的缩略图)
  • 左上角的 1 个图像(很小)(16 x 16?不完全确定)
  • 开始菜单停靠栏左侧的 1 个图像应用程序的大小(也许是 32x32?再次不确定)

所以没关系。

现在我选择了一个图标。在上述情况之一中我该如何使用它?

我尝试将其添加到资源中,但似乎没有任何反应。按照第一个 SO 解决方案,

“首先转到资源视图(从菜单:视图 --> 其他窗口 --> 资源视图)。然后在资源视图中导航资源(如果有)。如果已经存在图标类型的资源,由 Visual Studio 添加,然后打开并编辑它,否则右键单击并选择“添加资源”,然后添加一个新图标。”

资源视图是空的,我无法在此右键单击 。看法。

如果我右键单击解决方案>属性>资源>>我可以添加图标图像,但它没有显示在上面列出的任何位置。 (或我能看到的任何地方)

1) 如何设置 WPF 应用程序的应用程序图标?

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?

Set application icon from resources in VS 05

I am trying to set an icon for my application.

AFAIK, I need potentially 3 images?

  • 1 image is the actual image in explorer when clicking on the .exe (thumbnail for the exe)
  • 1 image (tiny) in the top left corner (16 x 16? Not entirely sure)
  • 1 image in the start menu dock, to the left of the app (maybe 32x32? again not sure)

So thats fine.

Now I have selected an 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,

"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."

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

镜花水月 2024-09-05 15:50:17

假设您使用 VS Express 和 C#。
该图标在项目属性页面中设置。要打开它,请右键单击解决方案资源管理器中的项目名称。在打开的页面中,有一个“应用程序”选项卡,在此选项卡中您可以设置图标。

Assuming you use VS Express and 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.

守望孤独 2024-09-05 15:50:17

@742 的答案效果很好,但正如注释中所述,从 VS 调试器运行时,通用图标仍然显示。

如果您希望即使在按 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">

在其中指示图标的路径(图标可以是 *.png*.ico。)

(请注意,您仍然需要设置应用程序图标,否则它仍然是资源管理器中的默认图标)。

@742's answer works pretty well, but as outlined in the comments when running from the VS debugger the generic icon is still shown.

If you want to have your icon even when you're pressing F5, you can add in the Main Window:

<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.)

(Note you will still need to set the Application Icon or it'll still be the default in Explorer).

为你鎻心 2024-09-05 15:50:17

注意:(将 file.ico 替换为您的实际图标文件名)

  1. 使用“资源”构建操作将图标添加到项目中。
  2. 在项目属性中,将应用程序图标设置为 file.ico
  3. 在主窗口 XAML 中设置:窗口上的 Icon=".\file.ico"

Note: (replace file.ico with your actual icon filename)

  1. Add the icon to the project with build action of "Resource".
  2. In the Project Properties, set the Application Icon to file.ico
  3. In the main Window XAML set: Icon=".\file.ico" on the Window
勿忘初心 2024-09-05 15:50:17

在收到带有消息的 XamlParseException 后:'使用给定的解决方案为'System.Windows.Baml2006.TypeConverterMarkupExtension'提供值,以编程方式设置图标对我有用。我就是这样做的:

  1. 将图标放入文件夹 <icon_path> 中在项目目录中
  2. 模拟文件夹路径 <icon_path>在解决方案中
  3. 在您创建的解决方案文件夹中添加一个新项目(您的图标)
  4. 在 WPF 窗口的代码后面添加以下代码:

Icon = new BitmapImage(new Uri("<icon_path>" , UriKind.Relative));

如果您在实施此解决方案时遇到任何困难,请告诉我,以便我提供帮助。

After getting a XamlParseException with message: 'Provide value on 'System.Windows.Baml2006.TypeConverterMarkupExtension' with the given solutions, setting the icon programmatically worked for me. This is how I did it:

  1. Put the icon in a folder <icon_path> in the project directory
  2. Mimic the folder path <icon_path> in the solution
  3. Add a new item (your icon) in the solution folder you created
  4. Add the following code in the WPF window's code behind:

Icon = new BitmapImage(new Uri("<icon_path>", UriKind.Relative));

Please inform me if you have any difficulties implementing this solution so I can help.

一页 2024-09-05 15:50:17

你也可以尝试这个:

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);
    }

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);
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文