C#UWP在ScrollViewer中显示x个ListView
所以我很不确定怎么画出这张图。 我认为他们在这里有一个ScrollView,在这个ScrollView中有不同的ListView 如何显示未知数量的这样组织的ListView 我甚至被困在如何只显示9张图片的部分,其中一张是大的。 我得到的只是:C#UWP在ScrollViewer中显示x个ListView,c#,listview,uwp,C#,Listview,Uwp,所以我很不确定怎么画出这张图。 我认为他们在这里有一个ScrollView,在这个ScrollView中有不同的ListView 如何显示未知数量的这样组织的ListView 我甚至被困在如何只显示9张图片的部分,其中一张是大的。 我得到的只是: <ScrollViewer Grid.Row="3" Grid.RowSpan="1" Grid.Column="0" Grid.ColumnSpan="4"&
<ScrollViewer Grid.Row="3"
Grid.RowSpan="1"
Grid.Column="0"
Grid.ColumnSpan="4">
<GridView Background="#fafafa"
SelectedItem="{Binding SelectedMovie,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
ItemsSource="{Binding Path=FilteredMoviesList, UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}"
IsSwipeEnabled="True">
<GridView.ItemTemplate>
<DataTemplate>
<Grid Margin="3"
Width="120"
Height="120">
<Grid>
<Rectangle Opacity="1"
Fill="White"
Height="120"
Width="120"/>
<Image Source="{Binding ImgSource}"
Width="120"
Height="190"
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
<Border BorderBrush="#161616"
Background="#16161601"
Opacity="0.9"
BorderThickness="0.1">
<StackPanel VerticalAlignment="Bottom"
Background="#000000">
<TextBlock Text="{Binding Name}"
Foreground="#f2f2f2"
HorizontalAlignment="Center"
FontWeight="Bold"
TextWrapping="Wrap"
Margin="2"
MaxWidth="120"
FontSize="13"/>
<TextBlock Text="{Binding DateOfShot}"
Foreground="#f2f2f2"
FontWeight="SemiBold"
HorizontalAlignment="Right"
FontSize="10"
Margin="0,0,10,0"/>
</StackPanel>
</Border>
<Rectangle Width="120"
Height="120"
Fill="#000000"
Opacity="0.1"/>
</Grid>
</Grid>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
</ScrollViewer>
显示所有项目
实现此布局有三个步骤 步骤1: 习惯于这样做 这是一个示例图像。资料来源: 语法 步骤3: 要限制
GridView
中的项目数量,请更改ItemsSource
。为此,您可以使用转换器
在XAML中
<Page.Resources>
<local:MyConverter x:Key="MyConverter"/>
</Page.Resources>
<GridView ItemsSource="{x:Bind ItemsSourceCollection, Converter={StaticResource MyConverter}}"/>
暗藏
public class MyConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
return (value as ObservableCollection<ItemSource>).Take(8);
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
公共类MyConverter:IValueConverter
{
公共对象转换(对象值、类型targetType、对象参数、字符串语言)
{
返回(值为ObservableCollection)。取(8);
}
公共对象转换回(对象值、类型targetType、对象参数、字符串语言)
{
抛出新的NotImplementedException();
}
}
有关更多信息:
对于示例项目:,一切都很简单。又是泰蒂!回答得好!嘿,丹尼尔,你有完整的源代码吗?
<Page.Resources>
<local:MyConverter x:Key="MyConverter"/>
</Page.Resources>
<GridView ItemsSource="{x:Bind ItemsSourceCollection, Converter={StaticResource MyConverter}}"/>
public class MyConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
return (value as ObservableCollection<ItemSource>).Take(8);
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}