2011-12-03 8 views
0

画像をリストボックスに読み込む必要があります。画像を選択すると問題が発生します。リストボックスには何もせずに枠線のみを追加し、コードとコレクション6のビットマップをデバッグしました。画像はありますが、境界線は1つしかありません。 1.That私のクラスのアルバムです:子供のための私のコード2.That画像をリストボックスにダイアログボックスで読み込みます。バインドに問題があります

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; 
     } 
    } 

私はボタンを作成押すwindow.When、私は名前、説明を書き、そしていくつかの写真を追加します(追加のための私の方法を確認してくださいがそれであります正しい)。私のXAML 4.That

private void CreateButton_Click(object sender, RoutedEventArgs e) 
{ 
    dialogAlbum = new DialogCreate(); 
    dialogAlbum.Show(); 
    dialogAlbum.Closed += delegate 
    { 
     albums.Add(new Album(dialogAlbum.TempName, dialogAlbum.TempDescription, dialogAlbum.Temps)); 
     AlbumScroll.ItemsSource = albums; 
     lsPhoto.ItemsSource = albums; 
    }; 
} 

:私はに戻っ

public partial class DialogCreate : ChildWindow 
    { 
     private List<BitmapImage> temps = new List<BitmapImage>(); 
     private string tempName; 
     private string tempDescription; 
     public List<BitmapImage> Temps 
     { 
      get { return temps; } 
      set { temps = value; } 
     } 
     public string TempName 
     { 
      get { return tempName; } 
      set { tempName = value; } 
     } 
     public string TempDescription 
     { 
      get { return tempDescription; } 
      set { tempDescription = value; } 
     } 
     private OpenFileDialog addPhoto; 
     public DialogCreate() 
     { 
      InitializeComponent(); 
      addPhoto = new OpenFileDialog(); 
      addPhoto.Multiselect = true; 
      addPhoto.Filter = "Image files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*"; 
     } 

     private void OKButton_Click(object sender, RoutedEventArgs e) 
     { 
      tempName = txtGetName.Text; 
      tempDescription = txtGetDescription.Text; 
      this.DialogResult = true; 
     } 
     private void CancelButton_Click(object sender, RoutedEventArgs e) 
     { 
      this.DialogResult = false; 
     } 
     private void AddButton_Click(object sender, RoutedEventArgs e) 
     { 
      bool result = (bool)addPhoto.ShowDialog(); 
      if (!result) 
       return; 
      IEnumerable<FileInfo> file = addPhoto.Files; 
      foreach (FileInfo files in file) 
      { 
       Stream s = files.OpenRead(); 
       BitmapImage i = new BitmapImage(); 
       i.SetSource(s); 
       temps.Add(i); 
      } 
     } 
    } 

3.After

<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> 

私が間違って何をしたか、私を助けたり、あなたの宣伝教えてください?。

+0

あなたは何をしようとしているかのように見えます。あなたはsomesortのスクロールビューアが必要です。http://deepumi.wordpress.com/2010/04/21/simple-image-scroller-slide-show-using-silverlight -listbox-control / – Nair

答えて

0

私は私は、これらの2つの変更やその他の影響を受けて変化して

<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> 

をあなたはBitmapImageのを使用するすべての場所を交換しMainPage.xamlをこの

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); 
    } 
} 

のような新しいクラスのものを作成しましたリストボックスには、ユーザーが選択したイメージが表示されます。私が試した解決策が必要な場合は、私にメールを送ってください。

関連する問題