-
Hi there! I'm trying to display a gallery of images using MVVM, thus I have the following structure code: <ScrollViewer VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<ItemsRepeater ItemsSource="{Binding Screenshots}">
<ItemsRepeater.Layout>
<WrapLayout />
</ItemsRepeater.Layout>
<ItemsRepeater.ItemTemplate>
<DataTemplate>
<Button Padding="0" ToolTip.ShowDelay="500" Height="150" Width="200" Margin="5">
<ToolTip.Tip>
<StackPanel Spacing="5">
<TextBlock
Text="{Binding Title}"
FontSize="20" FontWeight="SemiBold"/>
<TextBlock
Text="{Binding Path}"
FontSize="16"/>
</StackPanel>
</ToolTip.Tip>
<Image Stretch="UniformToFill" Source="{Binding Image}" />
</Button>
</DataTemplate>
</ItemsRepeater.ItemTemplate>
</ItemsRepeater>
</ScrollViewer> However, the ScrollViewer does not "work" as desired, as I guess it just encapsulates one child, the ItemRepeater. How can I make it work? I tried to find a Scroll Layout but found nothing yet. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 9 replies
-
Is there a StackPanel around the ScrollViewer by any chance? |
Beta Was this translation helpful? Give feedback.
-
I have a similar setup in one of my apps which works fine (although I am using a stack panel instead of a wrap panel). The scrolling however does get a bit awkward when using virtualisation without a fixed width for the the image control, as Avalonia has no idea how wide everything is until it tries to load it. As such the template looks like this: <ItemsRepeater.ItemTemplate>
<DataTemplate DataType="viewModels:Thumbnail">
<ListBoxItem Margin="2">
<Image Source="{CompiledBinding ThumbnailAsync^}" Width="200" />
</ListBoxItem>
</DataTemplate>
</ItemsRepeater.ItemTemplate> The key thing is a hardcoded width of 200. I imagine a similar thing would work for you. |
Beta Was this translation helpful? Give feedback.
look, there is a StackPanel around which is the issue here. Use a Grid and it should be okay