Ber*_*ryl 4 wpf xaml image visual-studio resource-editor
我对这个问题的动机实际上只是通过ImageSource的依赖属性指定要在用户控件中使用的图像.我正在遇到一些涉及管理,访问和单元测试的痛点.
Ray*_*rns 10
不,资源编辑器不是一个好的工具.
在WPF应用程序中,最好的方法是将所有图像放在"图像"目录中,并将每个图像标记为"资源".然后,您可以直接在图像控件和其他地方引用它们.
以下是精确的步骤:
现在,您可以在XAML中轻松引用图像:
<Image Source="Images/MyImage.png" />
Run Code Online (Sandbox Code Playgroud)
或者在代码中:
var source = (BitmapSource)Application.LoadComponent(
new Uri("Images/MyImage.png", UriKind.Relative));
Run Code Online (Sandbox Code Playgroud)
您还可以在外部装配中引用图像:
<Image Source="ReferencedAssembly;v1.0.0.1;component/Images/MyImage.png" />
Run Code Online (Sandbox Code Playgroud)
在代码中将是:
var source = (BitmapSource)Application.LoadComponent(
new Uri("ReferencedAssembly;v1.0.0.1;component/Images/MyImage.png",
UriKind.Relative));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5579 次 |
| 最近记录: |