在运行时将位图绑定到图像。 [英] Binding a bitmap to an image at runtime.

查看:57
本文介绍了在运行时将位图绑定到图像。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图在运行时绑定到一个图像并遇到问题,所以我回到了我认为基本的东西,但似乎无法让最简单的例子工作。


我查看了相关帖子,但似乎无法解决。


这有效:


<网格背景= "{StaticResource ApplicationPageBackgroundThemeBrush}">

    < Image Horizo​​ntalAlignment =" Left"高度= QUOT; 188"余量= QUOT; 344,316,0,0" VerticalAlignment = QUOT;陀螺"宽度= QUOT; 189"源= QUOT;资产/ PartPicture.png" />
$
< / Grid>


这使用带路径的变量/属性而不是。


< Grid Background =" {StaticResource ApplicationPageBackgroundThemeBrush}">

        < Image Horizo​​ntalAlignment =" 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提供的模板(项目页面等)绑定到变量并使用其他属性,但图像似乎更复杂。


史蒂夫。

解决方案

尝试:

 private string _imagePath =" /Assets/PartPicture.png" ;; 




如果想要改变它,别忘了实现INotifyPropertyChanged接口


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.

解决方案

try:

private string _imagePath = "/Assets/PartPicture.png";


and if want to change it dont forget to implement INotifyPropertyChanged interface


这篇关于在运行时将位图绑定到图像。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆