具有多图标的WPF应用程序
我已尝试使用以下步骤制作带有闪烁图标的wpf应用程序:具有多图标的WPF应用程序,wpf,windows,icons,Wpf,Windows,Icons,我已尝试使用以下步骤制作带有闪烁图标的wpf应用程序: 将Icon1.ico设置为项目属性中的应用程序图标 创建一个分派器 向Dispatchermer添加一个函数 在函数中,检查图标名称并对其进行更改 代码是这样的 private void ToggleIconVisibility(object sender, EventArgs e) { if (((BitmapImage)Icon).UriSource.OriginalString.CompareTo("Icon1
private void ToggleIconVisibility(object sender, EventArgs e)
{
if (((BitmapImage)Icon).UriSource.OriginalString.CompareTo("Icon1.ico") == 0)
{
Icon = new BitmapImage(new Uri("Icon2.ico", UriKind.RelativeOrAbsolute));
}
else
{
Icon = new BitmapImage(new Uri("Icon1.ico", UriKind.RelativeOrAbsolute));
}
}
当我在VisualStudio中运行它时,它工作得很好,但在发布应用程序后,找不到Icon2并崩溃了。两个图标文件都位于项目的根文件夹中。
如果有人能帮助我,我将不胜感激。我不知道您期望的图标是什么,或者您还有什么其他代码 当我在应用程序中设置图标时,你的代码对我不起作用 因此,我在标志中添加了一个int,该图标应为当前图标 我将我的两个图标文件设置为内容,如果更新,请复制 这意味着它们与exe一起被复制 然后,此代码对我有效:
private int currentIcon = 1;
private void Button_Click(object sender, RoutedEventArgs e)
{
if (currentIcon ==1 )
{
Icon = new BitmapImage(new Uri("Icon2.ico", UriKind.RelativeOrAbsolute));
currentIcon = 2;
return;
}
Icon = new BitmapImage(new Uri("Icon1.ico", UriKind.RelativeOrAbsolute));
currentIcon = 1;
}
您是否将图标作为资源包含到应用程序中?