Windows Phone 7 包装板可见性
我有一个以 gridview 样式显示一堆图像的列表,以下是我的代码:
<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 变量是否为空返回 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();
}
}
但是当我运行我的应用程序时,我得到了这个结果, 。第二个网格应该是不可见的,因为它包含空图像变量。
有谁知道如何禁用包装面板中的单个项目?非常感谢
编辑 我想我找到了我的问题的解决方案,在图像控件中定义宽度和高度而不是在wrappanel中,代码是
<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>
I have a list that displays a bunch of images in gridview style, the following is my code:
<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>
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:
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();
}
}
But When I run my app, I've got this result,. The second grid should be invisible because it contains null image variable.
Does anyone know how to disable individual item in wrappanel? Thanks a lot
Edit
I think I found the solution for my issue, define width and height in image control rather than in wrappanel, the code is
<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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先请修复您的转换器:
然后修复您的 XAML
First please fix your converter:
Then fix your XAML