如何在XAML中设置表单图标 [英] How can I set form Icon in xaml

查看:84
本文介绍了如何在XAML中设置表单图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为主窗口设置Icon属性. form.xaml位于\ Views文件夹下,而ico文件位于\ Resources文件夹下.
如何将其指向\ Resources \ GreenFlag.ico?

我意识到如果我复制了将ico文件保存为与表单相同的文件夹(在views文件夹下),则可以很好地进行以下操作:

< Window x:Class ="Pent.Views.MainView"
xmlns =" http://schemas.microsoft.com/winfx/2006/xaml/presentation "
xmlns:x =" http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:c =" clr-namespace:PGBuildClient.Commands""
Title =应用程序";
高度="230"宽度="535".图标="GreenFlag.ico". >

但是,似乎我不能执行Icon ="\ Resource \ GreenFlags.ico".我目前正在编写代码来执行此操作,但仍然想知道为什么它在xaml中不起作用?

干杯

I want to set the Icon attribute for the main window. The form.xaml is located under \Views folder and the ico file is under \Resources folder.
How can I point it to \Resources\GreenFlag.ico?

I realised if i copy the ico file to the same folder as the form (under views folder), then the following works fine:

<Window x:Class="Pent.Views.MainView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:c="clr-namespace:PGBuildClient.Commands"
    Title="Application"
    Height="230" Width="535" Icon="GreenFlag.ico" >

However, it seems that I can not do Icon="\Resource\GreenFlags.ico". I currently write code to do this, but still wanna know why it does not work in xaml?

Cheers

推荐答案

在XAML中,Icon ="\ Resource \ GreenFlags.ico".应该可以在没有调试(Ctrl + F5)模式的情况下工作.请参阅 http://msdn.microsoft .com/en-us/library/system.windows.window.icon.aspx 了解更多信息.

或图标="pack://application:,,//Resources/GreenFlags.ico"在调试或没有调试中工作.参见 http://msdn.microsoft.com/en-us/library/aa970069.aspx 有关更多信息.

In XAML, Icon="\Resource\GreenFlags.ico" should work in without Debugging (Ctrl+F5) mode. See the bottom of msdn Window.Icon Property link at http://msdn.microsoft.com/en-us/library/system.windows.window.icon.aspx for more info.

Or Icon="pack://application:,,,/Resources/GreenFlags.ico" works in debug or without debug. see http://msdn.microsoft.com/en-us/library/aa970069.aspx for more info.


这篇关于如何在XAML中设置表单图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆