我正在创建一个WPF窗口并在内部加载用户控件,如下所示:
Uri uri = new Uri("Views/ApplicationInfo.xaml", UriKind.RelativeOrAbsolute);
UserControl versionInfoUserControl = (UserControl)Application.LoadComponent(uri);
#region Initizalizing the Window, Winodw Proporties and Icon
Window versionWindow = new Window();
versionWindow.Height = 250;
versionWindow.Width = 400;
versionWindow.ResizeMode = ResizeMode.NoResize;
现在当我尝试添加如下所示的应用程序图标时:
versionWindow.Icon = new BitmapImage(new Uri(@"pack://application:,,component/Images/Ico.png"));
我收到的URI前缀无法识别错误。
*我是否需要使用应用程序名称更改应用程序,如:
versionWindow.Icon = new BitmapImage(new Uri(@"pack://MyApp.MVVM.WPF:,,component/Images/Ico.png"));
即便如此,我也收到同样的错误
答案 0 :(得分:4)
假设我有一个名为Assets的文件夹项目,并且内部有一个带有构建操作资源或嵌入式资源的png图像。
然后这个有效:
var versionWindow = new Window
{
Height = 250,
Width = 400,
ResizeMode = ResizeMode.NoResize,
Icon = new BitmapImage(new Uri(@"pack://application:,,,/Assets/icon.png"))
};
versionWindow.Show();
答案 1 :(得分:-1)
versionWindow.Icon = BitmapFrame.Create(new Uri("pack://application:,,,/YourProjectName;component/Images/computer.ico", UriKind.RelativeOrAbsolute))