首页 新闻 会员 周边

windows phone 的一个关于Image的问题

0
悬赏园豆:120 [已解决问题] 解决于 2013-02-21 10:39

我是动态binding的 image 的imagesoure

<ImageBrush ImageSource="{Binding Imgsrc}"></ImageBrush>

后台动态binding Imgsrc的值

Imgsrc="http://vote.ewang.com/voteimg/20130205053604.jpg"

 

以上会报错,但是如果下面这样就OK?不知道怎么回事,我是刚开始学windows phone,有明白人么,求解答。

<ImageBrush ImageSource="http://vote.ewang.com/voteimg/20130205053604.jpg"></ImageBrush>

雨风aa的主页 雨风aa | 初学一级 | 园豆:24
提问于:2013-02-19 10:11
< >
分享
最佳答案
0

 

 

 

 

刚才没看清你的问题呵呵 

如果是后台Binding Imgsrc的话

是绑定具体的图片,而你只是给的uri

你可以在后台把



    <ImageBrush ImageSource="{Binding Cover}" />



private ImageSource _cover;
public ImageSource Cover
{
    get
    {
        if (_cover == null)
        {
            _cover = new     System.Windows.Media.Imaging.BitmapImage(new Uri(@"http://vote.ewang.com/voteimg/20130205053604.jpg", UriKind.Relative));
          }
      return _cover;
   }
 }

 

 

 

收获园豆:120
li-peng | 小虾三级 |园豆:954 | 2013-02-19 10:27

你这个还是不对

List<helperClass.entity> list;

helperClass.entity enty;

public ImageSource Imgsrc { get; set; }

enty.Imgsrc = new BitmapImage(new Uri(@"http://vote.ewang.com/voteimg/20130205053604.jpg", UriKind.RelativeOrAbsolute));

循环去添加
              list.Add(enty);

界面

<ImageBrush ImageSource="{Binding Imgsrc}"></ImageBrush>

这样调试老是报错

雨风aa | 园豆:24 (初学一级) | 2013-02-19 10:54

@雨风aa: 

我看是一下是有问题 这么做在后台生成

你再用这个方法看一下,这试了没问题  后台代码写在加载事件里

 <Ellipse x:Name="ellipseWithImageBrush" Stroke="#FF000000" Height="150" Width="150">
               
            </Ellipse>
            ImageBrush imgBrush = new ImageBrush();

            imgBrush.ImageSource =
                            new BitmapImage(
                                new Uri(@"http://vote.ewang.com/voteimg/20130205053604.jpg", UriKind.Absolute)
                            );
            ellipseWithImageBrush.Fill = imgBrush;
li-peng | 园豆:954 (小虾三级) | 2013-02-19 11:10

@bluejance: 还是不行啊

雨风aa | 园豆:24 (初学一级) | 2013-02-19 12:22

@雨风aa: 

不对?不可能呀,我都试了,没问题的!你把这段代码放哪了?

ImageBrush imgBrush = new ImageBrush();

            imgBrush.ImageSource =
                            new BitmapImage(
                                new Uri(@"http://vote.ewang.com/voteimg/20130205053604.jpg", UriKind.Absolute)
                            );
            ellipseWithImageBrush.Fill = imgBrush;
li-peng | 园豆:954 (小虾三级) | 2013-02-19 12:23

@bluejance:  当前上下文中不存在ellipseWithImageBrush   我把它放在了PhoneApplicationPage_Loaded

雨风aa | 园豆:24 (初学一级) | 2013-02-19 12:28

@雨风aa: 

ellipseWithImageBrush   是Ellipse 的名字,你看看你的是不是多了空格什么的

不行你就自己起一个名字

x:Name="eA"

再把后台的代码

 ellipseWithImageBrush.Fill = imgBrush;
改成eA.Fill = imgBrush;
试试
li-peng | 园豆:954 (小虾三级) | 2013-02-19 12:32

@bluejance: 

<ImageBrush ImageSource="{Binding Imgsrc}"></ImageBrush> 我被包裹在一个ListBox里面的,我在后台用一个对象集合去绑定的ListBox Imgsrc 是一个对象的属性

雨风aa | 园豆:24 (初学一级) | 2013-02-19 12:43

@雨风aa: 

.....我给你说的这个方法能出图片了么?

li-peng | 园豆:954 (小虾三级) | 2013-02-19 12:48

@bluejance:  不行啊,后台还是找不到 Ellipse

雨风aa | 园豆:24 (初学一级) | 2013-02-19 12:48

@雨风aa: 

我这是没有问题的,你换一个别的控件试试

li-peng | 园豆:954 (小虾三级) | 2013-02-19 12:49

@bluejance:  图片显示出来了

雨风aa | 园豆:24 (初学一级) | 2013-02-19 12:51

@bluejance: 但是跟我这个问题有什么关系么

雨风aa | 园豆:24 (初学一级) | 2013-02-19 12:51

@雨风aa: 

你的问题不是说你在后能绑定不能显示图片么!

我这不是回答你为什么没显示出来图片么!!!

li-peng | 园豆:954 (小虾三级) | 2013-02-19 12:53

@bluejance:  但是你刚刚这个方法,如果放到ListBox 里就不行

雨风aa | 园豆:24 (初学一级) | 2013-02-19 12:55

@雨风aa: 

你就不能把那个方法改一下

在后台给ListBox 加ImageBrush

不就得了,为什么要把程序写的那么死

li-peng | 园豆:954 (小虾三级) | 2013-02-19 13:00

@bluejance:  哦,好像懂了

雨风aa | 园豆:24 (初学一级) | 2013-02-19 13:07

@bluejance:  还是不行,在后台怎么向 <ListBox.ItemTemplate>
                    <DataTemplate>

这里面添加控件啊
                    <DataTemplate/>

</ListBox.ItemTemplate>

雨风aa | 园豆:24 (初学一级) | 2013-02-20 16:47

@雨风aa: 

 <ListBox x:Name="myListBox">
               
 </ListBox>
            ImageBrush imgBrush = new ImageBrush();

            imgBrush.ImageSource =
                            new BitmapImage(
                                new Uri(@"http://vote.ewang.com/voteimg/20130205053604.jpg", UriKind.Absolute)
                            );
            ellipseWithImageBrush.Fill = imgBrush;
            ellipseWithImageBrush2.Fill = imgBrush;
            wordsWithImageBrush.Foreground = imgBrush;

            Ellipse _ell = new Ellipse();                              
            _ell.Fill = imgBrush;                                                                             
            myListBox.Items.Add(_ell);          

li-peng | 园豆:954 (小虾三级) | 2013-02-20 17:33

@bluejance:  直接用listbox.items.add() 这样不行啊,因为我还有里面的数据都是通过<ListBox.ItemTemplate>

<DataTemplate>

去绑定的,是不是得直接添加到datetemplate里面啊

雨风aa | 园豆:24 (初学一级) | 2013-02-21 10:06

@bluejance:  大哥,谢了,我找出原因了,分儿全给你

雨风aa | 园豆:24 (初学一级) | 2013-02-21 10:38

@雨风aa: 

做出来了就好,我没有做过windows phone程序,只做过wpf应用和ios,

我之前看过一些windows phone的文章 和wpf差不多

li-peng | 园豆:954 (小虾三级) | 2013-02-21 11:23
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册