在xaml中,它是:
<View:BaseWindow.Icon>
/VBDAdvertisement;component/Images/logoVBD.png
</View:BaseWindow.Icon>
我想把它转换成后台代码。
谢谢
发布于 2011-11-24 17:16:58
就像这样
myWindow.Icon = new BitmapImage(new Uri("/VBDAdvertisement;component/Images/logoVBD.png"));
不过,您可能需要对路径进行更多的限定。
编辑:我认为路径应该是pack-uri格式的:
"pack://application:,,,/VBDAdvertisement;component/Images/logoVBD.png"
发布于 2015-11-18 16:28:43
这是正确的方法(假设将MyIcon.ico放置在名为MyApplication的WPF项目的根文件夹中):
Uri iconUri = new Uri("pack://application:,,,/MyApplication;component/MyIcon.ico");
myWindow.Icon = BitmapFrame.Create(iconUri);
这也是在XAML中为窗口设置Icon属性时实际发生的情况。
当只是将图标设置为新的位图时,它将不会被平滑和正确地渲染,而是相当像素化。
发布于 2016-08-12 20:42:18
试试这个,它绝对适用于png和ico图像格式。
window.Icon = BitmapFrame.Create(Application.GetResourceStream(new Uri("LiveJewel.png", UriKind.RelativeOrAbsolute)).Stream);
https://stackoverflow.com/questions/8254281
复制相似问题