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

后端 未结 2 922
我寻月下人不归
我寻月下人不归 2021-01-22 11:22

I am creating a WPF window and loading a user control inside like below:

        Uri uri = new Uri(\"Views/ApplicationInfo.xaml\", UriKind.RelativeOrAbsolute);

         


        
相关标签:
2条回答
  • 2021-01-22 11:26
    versionWindow.Icon =  BitmapFrame.Create(new Uri("pack://application:,,,/YourProjectName;component/Images/computer.ico", UriKind.RelativeOrAbsolute))
    
    0 讨论(0)
  • 2021-01-22 11:43

    Assume I have a project with a folder named Assets and inside a have a png image with build action Resource or Embedded resource.

    Then this works:

    var versionWindow = new Window
                                    {
                                        Height = 250,
                                        Width = 400,
                                        ResizeMode = ResizeMode.NoResize,
                                        Icon = new BitmapImage(new Uri(@"pack://application:,,,/Assets/icon.png"))
                                    };
    
            versionWindow.Show();
    
    0 讨论(0)
提交回复
热议问题