Note that there are some explanatory texts on larger screens.

plurals
  1. POWindows Phone 7 Wrappanel visibility
    text
    copied!<p>I have a list that displays a bunch of images in gridview style, the following is my code:</p> <pre><code>&lt;controls:PanoramaItem x:Name="Pano_Photos" Header="photos"&gt; &lt;ListBox x:Name="lstMemoriesPhoto" ItemsSource="{Binding MemoryList}"&gt; &lt;i:Interaction.Triggers&gt; &lt;i:EventTrigger EventName="SelectionChanged" x:Name="ListPhotoSelectionChangedEventTrigger"&gt; &lt;GalaSoft_MvvmLight_Command:EventToCommand Command="{Binding NavigateToDetailPage}" PassEventArgsToCommand="True"/&gt; &lt;/i:EventTrigger&gt; &lt;/i:Interaction.Triggers&gt; &lt;ListBox.ItemsPanel&gt; &lt;ItemsPanelTemplate&gt; &lt;toolkit:WrapPanel ItemWidth="130" ItemHeight="130" Visibility="{Binding MemoryPhoto,Converter={StaticResource PhotoConverter}}"/&gt; &lt;/ItemsPanelTemplate&gt; &lt;/ListBox.ItemsPanel&gt; &lt;ListBox.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;Image Source="{Binding MemoryPhoto,Converter={StaticResource ByteImageConverter}}" Margin="5"/&gt; &lt;/DataTemplate&gt; &lt;/ListBox.ItemTemplate&gt; &lt;/ListBox&gt; &lt;/controls:PanoramaItem&gt; </code></pre> <p>The PhotoConverter checks MemoryPhoto variable and returns Visibility.Visible or Collapse depending on whether the MemoryPhoto variable is null or not. Here is the code for PhotoConverter:</p> <pre><code> public class PhotoConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { try { if ((value is byte[]) &amp;&amp; (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(); } } </code></pre> <p>But When I run my app, I've got this result,<img src="https://i.stack.imgur.com/4lRL7.png" alt="second grid should be invisible">. The second grid should be invisible because it contains null image variable.</p> <p>Does anyone know how to disable individual item in wrappanel? Thanks a lot</p> <p><strong>Edit</strong> I think I found the solution for my issue, define width and height in image control rather than in wrappanel, the code is</p> <pre><code>&lt;ListBox.ItemsPanel&gt; &lt;ItemsPanelTemplate&gt; &lt;toolkit:WrapPanel/&gt; &lt;/ItemsPanelTemplate&gt; &lt;/ListBox.ItemsPanel&gt; &lt;ListBox.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;Image Source="{Binding MemoryPhoto,Converter={StaticResource ByteImageConverter}}" Margin="5" Visibility="{Binding MemoryPhoto,Converter={StaticResource PhotoConverter}}" width="130" height="130"/&gt; &lt;/DataTemplate&gt; &lt;/ListBox.ItemTemplate&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload