Windows Phone 7 包装板可见性

发布于 2025-01-04 04:38:28 字数 2932 浏览 0 评论 0原文

我有一个以 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,second grid should be invisible. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

娇柔作态 2025-01-11 04:38:28

首先请修复您的转换器:

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;
            else
                return Visibility.Collapsed;
        }

        catch (Exception ex)
        {
            throw ex;
            return Visibility.Collapsed;
        }
    }

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

然后修复您的 XAML

<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"/>
            </ItemsPanelTemplate>
        </ListBox.ItemsPanel>
        <ListBox.ItemTemplate>
            <DataTemplate>
                <Image Source="{Binding MemoryPhoto,Converter={StaticResource ByteImageConverter}}" Visibility="{Binding MemoryPhoto, Converter={StaticResource PhotoConverter}}" Margin="5"/>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>        
</controls:PanoramaItem>

First please fix your converter:

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;
            else
                return Visibility.Collapsed;
        }

        catch (Exception ex)
        {
            throw ex;
            return Visibility.Collapsed;
        }
    }

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

Then fix your XAML

<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"/>
            </ItemsPanelTemplate>
        </ListBox.ItemsPanel>
        <ListBox.ItemTemplate>
            <DataTemplate>
                <Image Source="{Binding MemoryPhoto,Converter={StaticResource ByteImageConverter}}" Visibility="{Binding MemoryPhoto, Converter={StaticResource PhotoConverter}}" Margin="5"/>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>        
</controls:PanoramaItem>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文