0

我有一个图像列表,我需要将图像绑定到列表视图内的图像控制器。

我的 Xaml 代码

<ListView Name="lbxItems" SelectionChanged="ListBox_SelectionChanged_1" ItemsSource="{Binding Srcimg}">
                                <StackPanel>
                            <Image Name="item" Height="113" Source="{Binding}" Stretch="None"/>
                                </StackPanel>
                    </ListView>

代码隐藏文件

public void BindImgs()
        {
        //Some code here

            AClass a=new AClass();
            foreach (var photo in Photos)
            {
                Uri uri = new Uri(photo.ToString(), UriKind.Absolute); 
                a.Srcimg.Add(uri);
            }
            lbxItems.DataContext =a;
        }

    public class AClass
        {
            private List<Uri> _srcimg = new List<Uri>();

            public List<Uri> Srcimg
            {
                get { return _srcimg; }
            }
        }

当我运行应用程序时,它只显示 uri 字符串路径而不是显示图像。请帮忙!

4

1 回答 1

0

Change your Xaml to this and you should have more luck:-)

<ListView ItemsSource="{Binding Srcimg}">
    <ListView.ItemTemplate>
        <DataTemplate>
            <Image  Height="113" Source="{Binding}" Stretch="None"/>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>
于 2012-12-31T10:52:55.810 回答