0

我有这个 xaml 代码:

                <local:MyGridView x:Name="topDeal" ItemsSource="{Binding}" Margin="60,0,0,0" Grid.Row="1">
                    <GridView.ItemTemplate> 
                        <DataTemplate>
                            <Grid Margin="0">
                                <Grid.Background>
                                    <ImageBrush ImageSource="{Binding image1}"/>
                                </Grid.Background>

                                <StackPanel VerticalAlignment="Bottom" Background="#0072B0" Opacity="0.6">
                                    <Border BorderBrush="LightGray" BorderThickness="0,0,0,1"/>
                                    <TextBlock Text="{Binding name}" Foreground="white"/>
                                </StackPanel>
                            </Grid>
                        </DataTemplate>
                    </GridView.ItemTemplate>
                    <GridView.ItemsPanel>
                        <ItemsPanelTemplate>
                            <VariableSizedWrapGrid ItemHeight="180" ItemWidth="180" Orientation="Horizontal" MaximumRowsOrColumns="4"/>
                        </ItemsPanelTemplate>
                    </GridView.ItemsPanel>
                </local:MyGridView>

和后面的c#代码:

public class MyGridView : GridView
{

    protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
    {
        var gi = element as GridViewItem;
        //First griditem of MyGridView will be modified
        if (this.Items.IndexOf(item) == 0)
        {
            gi.SetValue(VariableSizedWrapGrid.ColumnSpanProperty, 2);
            gi.SetValue(VariableSizedWrapGrid.RowSpanProperty, 2);
        }
        base.PrepareContainerForItemOverride(gi, item);
    }
}

我想让第一个项目以其他项目的两倍大小显示,其中包含背景图像。此 链接中的结果。背景图像仅填充了 TextBlock。

在此处输入图像描述

4

1 回答 1

2

在您的数据模板中,您可以尝试这种方式,如果我没记错的话,它应该对您有用:

`<Border Background="{StaticResource ListViewItemPlaceholderBackgroundThemeBrush}" Margin="0,0,0,80"><Image Source="{Binding Image}" AutomationProperties.Name="{Binding Title}" Stretch="UniformToFill" Height="Auto" Width="Auto"/></Border>`
于 2012-10-29T07:26:15.927 回答