2016-07-23 6 views
1

이미지와 텍스트를 스택 패널에 표시하는 ComboBox가 있습니다. ComboBox를 처음 열 때 항목이 표시됩니다. 목록을 아래로 스크롤하면 목록의 맨 위에있는 항목의 이미지가 사라지고 (다시 스크롤하여 해당 항목을 볼 때) 그 반대의 경우도 마찬가지입니다. 텍스트는 그대로 유지됩니다. 또한 스크롤하지 않고도 콤보 상자에서 항목을 선택하면 해당 항목이 닫힌 콤보 상자에 이미지없이 표시됩니다. 어떻게 수정합니까?Combobox에서 이미지가 사라집니다.

<ComboBox ItemsSource="{Binding ElementName=searchPage, Path=emotionList}" 
           SelectionChanged="ComboBox_SelectionChanged" 
           Name="emotionComboBox" 
           VerticalAlignment="Center"> 
          <ComboBox.ItemTemplate> 
           <DataTemplate x:DataType="local:StorageItemThumbnailClass"> 
            <StackPanel Orientation="Horizontal"> 
             <Image Source="{Binding Thumbnail, Converter={StaticResource ImagetoThumbnailConverter}, Mode=OneWay}" Margin="10" MaxHeight="50" MaxWidth="50"/> 
             <TextBlock Text="{Binding Name}" Style="{StaticResource BodyTextBlockStyle}" Margin="10" TextWrapping="WrapWholeWords" Width="120"/> 
            </StackPanel> 
           </DataTemplate> 
          </ComboBox.ItemTemplate> 
         </ComboBox> 

이 방법은 콤보가 존재하는 searchPage의 OnNavigated 함수로부터 호출 - 여기

private async Task populateEmotionListAsync() 
     {    
      emotionList = new ObservableCollection<StorageItemThumbnailClass>(); 
      emotionList.Add(new StorageItemThumbnailClass { Name = EmotionEnum.None.ToString(), Thumbnail = null }); 
      emotionList.Add(new StorageItemThumbnailClass { Name = EmotionEnum.Angry.ToString(), Thumbnail = await (await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/EmotionIcons/angry.png"))).GetThumbnailAsync(ThumbnailMode.PicturesView, 50) }); 
      emotionList.Add(new StorageItemThumbnailClass { Name = EmotionEnum.Contempt.ToString(), Thumbnail = await (await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/EmotionIcons/contempt.png"))).GetThumbnailAsync(ThumbnailMode.PicturesView, 50) }); 
      emotionList.Add(new StorageItemThumbnailClass { Name = EmotionEnum.Disgusted.ToString(), Thumbnail = await (await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/EmotionIcons/disgust.png"))).GetThumbnailAsync(ThumbnailMode.PicturesView, 50) }); 
      emotionList.Add(new StorageItemThumbnailClass { Name = EmotionEnum.Afraid.ToString(), Thumbnail = await (await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/EmotionIcons/afraid.png"))).GetThumbnailAsync(ThumbnailMode.PicturesView, 50) }); 
      emotionList.Add(new StorageItemThumbnailClass { Name = EmotionEnum.Happy.ToString(), Thumbnail = await (await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/EmotionIcons/happy.png"))).GetThumbnailAsync(ThumbnailMode.PicturesView, 50) }); 
      emotionList.Add(new StorageItemThumbnailClass { Name = EmotionEnum.Neutral.ToString(), Thumbnail = await (await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/EmotionIcons/neutral.png"))).GetThumbnailAsync(ThumbnailMode.PicturesView, 50) }); 
      emotionList.Add(new StorageItemThumbnailClass { Name = EmotionEnum.Sad.ToString(), Thumbnail = await (await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/EmotionIcons/sad.png"))).GetThumbnailAsync(ThumbnailMode.PicturesView, 50) }); 
      emotionList.Add(new StorageItemThumbnailClass { Name = EmotionEnum.Surprised.ToString(), Thumbnail = await (await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/EmotionIcons/surprised.png"))).GetThumbnailAsync(ThumbnailMode.PicturesView, 50) }); 
     } 

는 StorageItemThumbnailClass 인 -

public class StorageItemThumbnailClass : INotifyPropertyChanged 
{ 
    public event PropertyChangedEventHandler PropertyChanged; 
    private StorageItemThumbnail _thumbnail; 
    private string _name; 

    public StorageItemThumbnail Thumbnail 
    { 
     get { return _thumbnail; } 
     set 
     { 
      _thumbnail = value; 
      // Call OnPropertyChanged whenever the property is updated 
      OnPropertyChanged("Thumbnail"); 
     } 
    } 

    // Create the OnPropertyChanged method to raise the event 
    protected void OnPropertyChanged(string name) 
    { 
     PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); 
    } 

    public String Name 
    { 
     get { return _name; } 
     set 
     { 
      _name = value; 
      // Call OnPropertyChanged whenever the property is updated 
      OnPropertyChanged("Name"); 
     } 
    } 
} 

그리고 여기 변환기 - 인

답변

1

이 문제를 해결할 수있었습니다. ComboBox는 UI 가상화를 수행하고 ComboBox의 가상화 된 패널에있는 이미지는 스크롤하지 않고 볼 때 제거되었습니다. 다시 스크롤하면 제거 된 이미지 변환기가 다시 호출되고 이미지 소스가 재설정되었습니다. 따라서 소스로 사용 된 스트림은 재사용을 위해 시작 위치로 설정해야했습니다.

변환기 -

StorageItemThumbnail thumbnail = (StorageItemThumbnail)value; 
thumbnail.Seek(0); 
image = new BitmapImage(); 
image.SetSource(thumbnail); 
관련 문제