在用户控制图像中设置图像源. [英] Set Image Source in User Control Image.

查看:64
本文介绍了在用户控制图像中设置图像源.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我在Silverlight中工作.

我创建了两个项目.一个项目包含用户控件.通过提供参考,我在另一个包含Image文件夹的项目中使用了该用户控件.现在,我想在UserControl中使用Image.如何动态设置?

这是我的用户控件:

Xaml页面:
<图片x:Name ="imgDisplay" Horizo​​ntalAlignment ="Stretch" VerticalAlignment ="Stretch"
Grid.Row ="1" Grid.Column ="1" Height ="Auto" Width ="Auto" Margin ="0" Source ="../Images/Email.png"/>


Xaml.cs页:

Hi,
I am working in Silverlight.

I have created two projects. One project contains user control. By giving reference, I am using that user control in my another project which also contains Image folder. Now, I want to use Image in my UserControl. How can i set it dynamically?

Here is my user control:

Xaml page:
<Image x:Name="imgDisplay" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
Grid.Row="1" Grid.Column="1" Height="Auto" Width="Auto" Margin="0" Source="../Images/Email.png" />


Xaml.cs page:

public partial class exTile : UserControl
    {
        
        public ImageSource ImagePath
        {
            get { return imgDisplay.Source; }

            set
            {
                this.imgDisplay.Source = value;
            }
        }

    }




我使用UserControl并将其命名为objTilesEmail的页面.




My page where i have used my UserControl and named as objTilesEmail.

exTile objTilesEmail = new exTile();
objTilesEmail.ImagePath = new System.Windows.Media.Imaging.BitmapImage(newUri("../Image/Email.png",UriKind.Relative));

推荐答案

您可以尝试...


You can try this...


exTile objTilesEmail = new exTile();
objTilesEmail.ImagePath = new System.Windows.Media.Imaging.BitmapImage (new Uri("/Repairs;component/Themes/PurpleTheme/Images/Email.png", UriKind.Relative));


这篇关于在用户控制图像中设置图像源.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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