问题描述
我一直试图在运行时绑定到一个图像并遇到问题,所以我回到了我认为基本的东西,但似乎无法让最简单的例子工作。
我查看了相关帖子,但似乎无法解决。
这有效:
<网格背景= "{StaticResource ApplicationPageBackgroundThemeBrush}">
< Image HorizontalAlignment =" Left"高度= QUOT; 188"余量= QUOT; 344,316,0,0" VerticalAlignment = QUOT;陀螺"宽度= QUOT; 189"源= QUOT;资产/ PartPicture.png" />
$
< / Grid>
这使用带路径的变量/属性而不是。
< Grid Background =" {StaticResource ApplicationPageBackgroundThemeBrush}">
< Image HorizontalAlignment =" Left"高度= QUOT; 188"余量= QUOT; 344,316,0,0" VerticalAlignment = QUOT;陀螺"宽度= QUOT; 189" Source =" {Binding imagePath}" />
$
< / Grid>
代码背后:
私有字符串_imagePath =" Assets / PartPicture .png" ;;
$
public string imagePath {get {return _imagePath; } set {_imagePath = value;我注意到Microsoft提供的模板(项目页面等)绑定到变量并使用其他属性,但图像似乎更复杂。
史蒂夫。
I have been trying to bind to an image at runtime and having problems so I went back to what I thought was basics but can't seem to make the simplest example work.
I have looked at the relevant posts but can't seem to work it out.
This works:
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<Image HorizontalAlignment="Left" Height="188" Margin="344,316,0,0" VerticalAlignment="Top" Width="189" Source="Assets/PartPicture.png" />
</Grid>
this uses a variable/property with the path and doesn't.
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<Image HorizontalAlignment="Left" Height="188" Margin="344,316,0,0" VerticalAlignment="Top" Width="189" Source="{Binding imagePath}" />
</Grid>
Code behind:
private string _imagePath = "Assets/PartPicture.png";
public string imagePath { get { return _imagePath; } set { _imagePath = value; } }
I have noticed that the templates Microsoft supply (Item Pages, etc) bind to variables and am using other properties with these but the image seems to be more complicated.
Steve.
这篇关于在运行时将位图绑定到图像。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!