Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从Phone类库访问图像_C#_Xaml_Visual Studio 2012_Windows 8_Windows Phone 8 - Fatal编程技术网

C# 从Phone类库访问图像

C# 从Phone类库访问图像,c#,xaml,visual-studio-2012,windows-8,windows-phone-8,C#,Xaml,Visual Studio 2012,Windows 8,Windows Phone 8,我已经用MainPage.xaml创建了一个电话类库(名称为Base)。我正在子项目中链接此文件。由于所有的类文件都是从基链接的,所以我能够运行子项目 我面临的问题是,我想从我的子项目(在我的子项目中)访问图像文件。例如,我的子项目的图像位于Assets文件夹中。我的代码是 Image image = new Image(); Uri imageUri = new Uri("Assets/Topic1.png", UriKind.Relative); image.Source = new Bit

我已经用MainPage.xaml创建了一个电话类库(名称为Base)。我正在子项目中链接此文件。由于所有的类文件都是从基链接的,所以我能够运行子项目

我面临的问题是,我想从我的子项目(在我的子项目中)访问图像文件。例如,我的子项目的图像位于Assets文件夹中。我的代码是

Image image = new Image();
Uri imageUri = new Uri("Assets/Topic1.png", UriKind.Relative);
image.Source = new BitmapImage(imageUri);
image.Width = 48;
image.Height = 48;
ContentPanelChildren.Add(image);
这段代码不显示位于“Assets/Topic1.png”位置的我的图像

如何显示图像


谢谢。

尝试将Uri行更改为:

Uri imageUri = new Uri("/ASSEMBLY NAME;component/Assets/Topic1.png", UriKind.Relative);
用程序集的名称替换“程序集名称”