2

我有一个WPF项目,其中应用程序图标是使用转换器从特定路径获取的,请找到示例代码块。

主窗口.xaml.cs

Icon="{Binding Converter={StaticResource IconToImageConverter}}"

转换器类:

public class IconToImageConverter : IValueConverter
{
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return new BitmapImage(new Uri(TheIconPath)); 
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
}

我们可以随时替换特定路径中的图标,它会在我们下次从bin 文件夹或 Visual Studio 运行应用程序时反映在任务栏中。

我们有这个应用程序的安装程序,它为应用程序创建桌面快捷方式图标。现在似乎任务栏图标仅取自桌面快捷方式图标,并且它永远不会根据放置在特定路径上的图标而改变。

我的要求是我需要从特定路径引用图标,因为它在 bin 或 Visual Studio 上的行为。

4

0 回答 0