[C# Markup] items repeater inconsistent item types between Desktop and Windows #2416
-
Create public MainPage()
{
this
.Background(ThemeResource.Get<Brush>("ApplicationPageBackgroundThemeBrush"))
.Content(new StackPanel()
.VerticalAlignment(VerticalAlignment.Center)
.HorizontalAlignment(HorizontalAlignment.Center)
.Children(
new TextBlock()
.HorizontalAlignment(HorizontalAlignment.Center)
.Text("Hello Uno Platform!"),
new ItemsRepeater()
//.Layout(new StackLayout()) // works fine
.Layout(new MyLayout()) // works fine, using my layout let me to inspect created items
.HorizontalAlignment(HorizontalAlignment.Center)
.ItemsSource(Enumerable.Range(0, 5))
.ItemTemplate<int>(item =>
new TextBlock()
.HorizontalAlignment(HorizontalAlignment.Center)
.Text(() => $"Item {item}"))
));
} This works fine under Using my own layout let me to inspect created items: public class MyLayout : NonVirtualizingLayout
{
protected override Size MeasureOverride(NonVirtualizingLayoutContext context, Size availableSize)
{
double extentHeight = 0.0;
double extentWidth = 0.0;
foreach (UIElement element in context.Children)
{
element.Measure(availableSize);
extentHeight += element.DesiredSize.Height;
extentWidth = Math.Max(extentWidth, element.DesiredSize.Width);
}
return new Size(extentWidth, extentHeight);
}
protected override Size ArrangeOverride(NonVirtualizingLayoutContext context, Size finalSize)
{
double offset = 0.0;
foreach (FrameworkElement element in context.Children.Cast<FrameworkElement>())
{
element.Arrange(new Rect(0, offset, element.DesiredSize.Width, element.DesiredSize.Height));
offset += element.DesiredSize.Height;
// inspect the type of element
Debug.WriteLine($"element type: {element.GetType().Name}");
Debug.WriteLine($"element.DataContext: {element.DataContext}");
}
return finalSize;
}
} Surprisingly the type of element differs between
The
|
Beta Was this translation helpful? Give feedback.
Answered by
morning4coffe-dev
Jul 25, 2024
Replies: 1 comment 1 reply
-
@kucint Thank you for reporting this. I will have a look on the details. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@kucint I had a bit deeper look at this issue today and I can confirm this behavior is happening on the
NonVirtualizingLayout
, but only with C# Markup. Testing this with a similar layout using Xaml, this issue doesn't seem to reproduce. I opened an issue #2458 to track this further.