-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DataTemplate adaptation is wrong in ItemsRepeater #14
Comments
As a workaround: would a Converter help you instead of two DataTemplates? |
@timuenie The sample I presented is a minimally reproducible code. For example. Here's another one I made up artificially <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled">
<ItemsRepeater Items="{Binding Items}">
<ItemsRepeater.Layout>
<UniformGridLayout MinItemWidth="60" MinItemHeight="30" Orientation="Vertical" />
</ItemsRepeater.Layout>
<ItemsRepeater.ItemTemplate>
<views:DataTemplateSelector>
<views:DataTemplateSelector.Under100DataTemplate>
<DataTemplate DataType="viewModels:DataViewModel">
<StackPanel Width="60" Orientation="Horizontal">
<Rectangle
Width="16"
Height="16"
Fill="Red" />
<TextBlock Foreground="Red" Text="{Binding Index}" />
</StackPanel>
</DataTemplate>
</views:DataTemplateSelector.Under100DataTemplate>
<views:DataTemplateSelector.Over100DataTemplate>
<DataTemplate DataType="viewModels:DataViewModel">
<Button
Content="{Binding Index}"
Foreground="Green" />
</DataTemplate>
</views:DataTemplateSelector.Over100DataTemplate>
</views:DataTemplateSelector>
</ItemsRepeater.ItemTemplate>
</ItemsRepeater>
</ScrollViewer> 2022-09-17-08-44-20.mp4Does your workaround still work in this situation? |
I also have a workaround for this situation. Just to be clear: I didn't say here you have a workaround, so this issue doesn't need to be fixed. But at the moment there are lots of efforts going on to prepare 11.0, so I don't know when this issue gets addressed. If you know a solution, PRs are welcome 🤗 My other workaround only works if you have two different DataTemplates: place both different controls into one DataTemplate and bind their IsVisible to the bool property you have. And I have a third option: Use Avalonia.Behaviors Happy coding |
Related? #6 |
@timuenie I was able to isolate whether this problem was on the Avalonia side or my implementation. Thanks for the workaround suggestion. ItemsControl does not work with virtualization, but the rest of the operation is as desired. I will consider the ItemsRepeater issue after I have more knowledge of Avalonia myself. Or I will implement a panel that virtualization works. Avalonia.Behaviors was my first attempt at using Avalonia. I myself am an experienced WPF user and tried to handle this with DataTriggerBehavior, but had the same problem. Thank you again for your help. |
Describe the bug
DataTemplate adaptation is wrong in ItemsRepeater.
Reproduction project
https://github.com/YoshihiroIto/AvaloniaDataTemplateProblem
This project works as follows
Numbers below 100 are displayed in red.
Numbers above 100 are displayed in green.
When the Add Items button is clicked, 10 items are added.
When the Remove Items button is clicked, 10 items are removed.
To Reproduce
After adding and deleting items several times, the colors are displayed incorrectly.
Expected behavior
After repeated addition and deletion of items, below 100 are displayed in red, and above 100 are displayed in green.
Screenshots
2022-09-16-21-00-37.mp4
Desktop
OS: Windows 11
Avalonia: 11.0.0-preview1
The text was updated successfully, but these errors were encountered: