Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Silverlight 通过对话框将图像加载到列表框。绑定有问题_Silverlight_Image_Binding_Listbox_Load - Fatal编程技术网

Silverlight 通过对话框将图像加载到列表框。绑定有问题

Silverlight 通过对话框将图像加载到列表框。绑定有问题,silverlight,image,binding,listbox,load,Silverlight,Image,Binding,Listbox,Load,我应该将图像加载到listbox。我在选择图像时遇到问题,listbox只添加了边框,没有任何内容,只有一个,我已经调试了我的代码和集合中的6个位图图像,但只加载了1个边框。 1.那是我的班级相册: public class Album : INotifyPropertyChanged { private string name; public string Name { get { return name;

我应该将图像加载到listbox。我在选择图像时遇到问题,listbox只添加了边框,没有任何内容,只有一个,我已经调试了我的代码和集合中的6个位图图像,但只加载了1个边框。 1.那是我的班级相册:

  public class Album : INotifyPropertyChanged
    {
        private string name;
        public string Name 
        {
            get { return name; }
            set 
            { 
                name = value;
                OnPropertyChanged(new PropertyChangedEventArgs("Name"));
            }
        }
        private string description;
        public string Description 
        { 
            get
            {
                return description;
            }
            set 
            {
                description = value;
                OnPropertyChanged(new PropertyChangedEventArgs("Description"));
            } 
        }
        private List<BitmapImage> images;
        public List<BitmapImage> Images
        {
            get
            {
                return images;
            }
            set
            {
                images = value;
                OnPropertyChanged(new PropertyChangedEventArgs("Images"));
            }
        }
        public event PropertyChangedEventHandler PropertyChanged;
        public void OnPropertyChanged(PropertyChangedEventArgs e)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, e);
        }
        public Album() { }
        public Album(string name, string description, List<BitmapImage> files)
        {
            Name = name;
            Description = description;
            Images = files;
        }
    }
4.我的xaml:

<ListBox Style="{StaticResource ListBoxStyle}" ItemsSource="{Binding Images}" Margin="121,38,171,23" x:Name="lsPhoto" Grid.Column="1" Grid.Row="2" Height="144" Width="600">
        <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel Orientation="Horizontal"/>
            </ItemsPanelTemplate>
        </ListBox.ItemsPanel>
        <ListBox.ItemTemplate>
            <DataTemplate>
                  <Border Width="100" Height="100">
                    <Image x:Name="listPhotos" Source="{Binding}" Width="Auto" Height="Auto"/>
                  </Border>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>


请帮帮我,我做错了什么?或者给你做广告。

我创建了一个类似这样的新类

public class ImageInformation:INotifyPropertyChanged
{
    public string Name { get; set; }
    public BitmapImage ImageInfo { get; set; }

    public event PropertyChangedEventHandler PropertyChanged;
    public void OnPropertyChanged(PropertyChangedEventArgs e)
    {
        if (PropertyChanged != null)
            PropertyChanged(this, e);
    }
}
我替换了您在mainpage.xaml中使用BitmapImage和的所有位置

<ListBox x:Name="lsPhoto" Grid.RowSpan="2">
        <ListBox.ItemTemplate>
            <DataTemplate>

                <StackPanel Height="25" Width="25">

                    <Image Height="25" Width="25" Source="{Binding ImageInfo}"></Image>

                </StackPanel>

            </DataTemplate>

        </ListBox.ItemTemplate>
    </ListBox>


通过这两个更改和其他受影响的更改,“我的列表框”显示用户选择的图像。如果您需要我尝试过的解决方案,请给我发一封邮件。

看起来您正在尝试的是,您需要某种滚动查看器
public class ImageInformation:INotifyPropertyChanged
{
    public string Name { get; set; }
    public BitmapImage ImageInfo { get; set; }

    public event PropertyChangedEventHandler PropertyChanged;
    public void OnPropertyChanged(PropertyChangedEventArgs e)
    {
        if (PropertyChanged != null)
            PropertyChanged(this, e);
    }
}
<ListBox x:Name="lsPhoto" Grid.RowSpan="2">
        <ListBox.ItemTemplate>
            <DataTemplate>

                <StackPanel Height="25" Width="25">

                    <Image Height="25" Width="25" Source="{Binding ImageInfo}"></Image>

                </StackPanel>

            </DataTemplate>

        </ListBox.ItemTemplate>
    </ListBox>