簡體   English   中英

無法識別URI前綴設置WPF UserControl圖標時出錯

[英]The URI prefix is not recognized Error While Setting WPF UserControl Icon

我正在創建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"));

即使那樣我也遇到同樣的錯誤

假設我有一個項目,其中有一個名為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();
versionWindow.Icon =  BitmapFrame.Create(new Uri("pack://application:,,,/YourProjectName;component/Images/computer.ico", UriKind.RelativeOrAbsolute))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM