グリッドビュースタイルで一連の画像を表示するリストがあります。以下は私のコードです。
<controls:PanoramaItem x:Name="Pano_Photos" Header="photos">
<ListBox x:Name="lstMemoriesPhoto" ItemsSource="{Binding MemoryList}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged" x:Name="ListPhotoSelectionChangedEventTrigger">
<GalaSoft_MvvmLight_Command:EventToCommand Command="{Binding NavigateToDetailPage}" PassEventArgsToCommand="True"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<toolkit:WrapPanel ItemWidth="130" ItemHeight="130" Visibility="{Binding MemoryPhoto,Converter={StaticResource PhotoConverter}}"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<Image Source="{Binding MemoryPhoto,Converter={StaticResource ByteImageConverter}}" Margin="5"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</controls:PanoramaItem>
PhotoConverterはMemoryPhoto変数をチェックし、MemoryPhoto変数がnullかどうかに応じて、Visibility.VisibleまたはCollapseを返します。PhotoConverterのコードは次のとおりです。
public class PhotoConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
try
{
if ((value is byte[]) && (value != null))
{
return Visibility.Visible;
}
return Visibility.Collapsed;
}
catch (Exception ex)
{
throw ex;
}
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
しかし、アプリを実行すると、この結果が得られます。2番目のグリッドにはnull画像変数が含まれているため、非表示にする必要があります。
ラップパネルで個々のアイテムを無効にする方法を知っている人はいますか?どうもありがとう
編集 私は私の問題の解決策を見つけたと思います、ラップパネルではなく画像コントロールで幅と高さを定義します、コードは
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<toolkit:WrapPanel/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<Image Source="{Binding MemoryPhoto,Converter={StaticResource ByteImageConverter}}" Margin="5" Visibility="{Binding MemoryPhoto,Converter={StaticResource PhotoConverter}}" width="130" height="130"/>
</DataTemplate>
</ListBox.ItemTemplate>