1

我有 5 个水平列表框,其中包含图像和文本.. 文本显示在 stackpanel 内的文本块中(背景为灰色).. 现在如果我将背景更改为黑色,不透明度更改为 0.3,我开始内存不足.. 可能是什么错误的??这是我的列表框:

<ScrollViewer x:Name="scroll1" HorizontalAlignment="Left" Height="200" Margin="0,27,0,0" VerticalAlignment="Top" Width="480" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled" >
<ListBox Name="firstList" Height="200" ScrollViewer.VerticalScrollBarVisibility="Disabled" Tap="firstList_SelectionChanged_1" >
<toolkit:GestureService.GestureListener>
    <toolkit:GestureListener DragCompleted="GestureListener_DragCompleted"></toolkit:GestureListener>
</toolkit:GestureService.GestureListener>
<ListBox.ItemsPanel>
    <ItemsPanelTemplate>
        <StackPanel Orientation="Horizontal" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Disabled" />
    </ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemContainerStyle>
    <Style TargetType="ListBoxItem">
        <Setter Property="Padding" Value="0 0 0 0 " />
    </Style>
</ListBox.ItemContainerStyle>

<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical" Height="200" Width="150" Background="Transparent">
    <!--Replace rectangle with image-->
    <Image Source="{Binding image}" Margin="0,20" HorizontalAlignment="Left" VerticalAlignment="Bottom" Stretch="UniformToFill" Height="140" Width="119"></Image>
    <Grid Margin="0,-335,0,0" HorizontalAlignment="Center" Background="Transparent" Height="30">
        <TextBlock Text="{Binding brandName}" HorizontalAlignment="Center" FontSize="15"  TextWrapping="NoWrap" Foreground="#FFAA1F17" />
    </Grid>
    <Grid Margin="70,-240,-10,0" Width="50" Height="50" Background="Transparent">
    <!--<TextBlock Text="Discount" Foreground="White" FontSize="15" Margin="15,0,5,0"/>-->
        <Image Source="{Binding imageSource}"  Width="50" Height="50" ></Image>
        <TextBlock Text="{Binding discountPercentage}" TextWrapping="NoWrap" HorizontalAlignment="Center" VerticalAlignment="Center"  Foreground="White" FontSize="15" />
    </Grid>
    <StackPanel Width="150" Margin="0,-35,0,0" Background="Transparent">

        <Grid HorizontalAlignment="Stretch" Height="55" Background="#FF9B9A9A">
         <!--<TextBlock Text="Rs" Foreground="White" FontSize="20" Margin="30,0,5,0"/>-->
            <StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center" Background="Transparent">
                <TextBlock Text="{Binding productName}" TextWrapping="Wrap" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="#99FFFFFF" FontSize="15" />
            </StackPanel>
        </Grid>

    </StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</ScrollViewer>

我试过这个并且得到了内存不足的错误:

<StackPanel Orientation="Vertical" Height="200" Width="150" Background="Transparent">
<!--Replace rectangle with image-->
<Image Source="{Binding image}" Margin="0,20" HorizontalAlignment="Left" VerticalAlignment="Bottom" Stretch="UniformToFill" Height="140" Width="119"></Image>
<Grid Margin="0,-335,0,0" HorizontalAlignment="Center" Background="Transparent" Height="30">
    <TextBlock Text="{Binding brandName}" HorizontalAlignment="Center" FontSize="15"  TextWrapping="NoWrap" Foreground="#FFAA1F17" />
</Grid>
<Grid Margin="70,-240,-10,0" Width="50" Height="50" Background="Transparent">
    <!--<TextBlock Text="Discount" Foreground="White" FontSize="15" Margin="15,0,5,0"/>-->
    <Image Source="{Binding imageSource}"  Width="50" Height="50" ></Image>
    <TextBlock Text="{Binding discountPercentage}" TextWrapping="NoWrap" HorizontalAlignment="Center" VerticalAlignment="Center"  Foreground="White" FontSize="15" />
</Grid>
<StackPanel Width="150" Margin="0,-35,0,0" Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center" Background="Black" Opacity="0.3">

<TextBlock Text="{Binding productName}" TextWrapping="Wrap" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="#99FFFFFF" FontSize="15" />

</StackPanel>
</StackPanel>
4

1 回答 1

0

自我解决。通过在透明图像上用文本块替换网格/堆栈面板。

于 2013-10-10T09:01:31.053 回答