C# 如何在库中的代码隐藏中设置图像源?
我有一个用C#for Windows 8编写的类库,其中有一个自定义控件和一个名为Images的文件夹,其中包含一堆图像。在控制模板中,我有一个图像C# 如何在库中的代码隐藏中设置图像源?,c#,windows-8,windows-runtime,bitmapimage,C#,Windows 8,Windows Runtime,Bitmapimage,我有一个用C#for Windows 8编写的类库,其中有一个自定义控件和一个名为Images的文件夹,其中包含一堆图像。在控制模板中,我有一个图像 <ControlTemplate TargetType="local:MyCustomControl"> <Grid Background="Transparent"> <Image x:Name="MyImage" Height="{TemplateBinding
<ControlTemplate TargetType="local:MyCustomControl">
<Grid Background="Transparent">
<Image x:Name="MyImage"
Height="{TemplateBinding Height}"
Width="{TemplateBinding Width}"
Stretch="Fill" />
...
</Grid>
</ControlTemplate>
this.MyImage.Source = new BitmapImage(new Uri(this.BaseUri, imagePath));
this.MyImage.Source = new BitmapImage(new Uri(imagePath, UriKind.Relative));
ms资源
uri方案我怎样才能做到这一点呢?好的,这很快就升级了。:)也许,对其他人会有用。 解决方案是在路径中使用库的程序集名称:
var assemblyName = this.GetType().GetTypeInfo().Assembly.GetName().Name;
this.MyImage.Source = new BitmapImage(new Uri(this.BaseUri, assemblyName + imagePath));