最近在MXS里用WPF写了UI,图片资源都是在Xaml里写绝对路径,这样子不方便而且容易报错
下面这个方法可以在MXS里正确加载图片资源
这是UI
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid Background="Black">
<Image x:Name="image2" HorizontalAlignment="Left" Height="100" Margin="189,102,0,0" VerticalAlignment="Top" Width="100"/>
</Grid>
</Window>
在MXS里的代码
tempStr= "<Window
xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"
xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\"
Title=\"MainWindow\" Height=\"350\" Width=\"525\">
<Grid Background=\"Black\">
<Image x:Name=\"image2\" HorizontalAlignment=\"Left\" Height=\"100\" Margin=\"189

本文介绍了在MXS中使用WPF UI时如何正确加载和管理图片资源,特别是在处理Image和Button的Background属性时的解决办法。通过引用方法,解决了设置ImageSource和ImageBrush时遇到的问题,参考了相关博客资源。
最低0.47元/天 解锁文章
6万+

被折叠的 条评论
为什么被折叠?



