question

ShereifAwad-5223 avatar image
0 Votes"
ShereifAwad-5223 asked ·

list of absolute layout children

I have muliple sheets with cutted boxes in specific positions in each sheet

I use code behind to display it

     private void paint(List<StockSheet> results)
     {
         // Create SKCanvasView to view result
         SheetsNumber = results.Count().ToString();
         //int row = 1;
         foreach (var sheet in results)
         {
             var absolute = new AbsoluteLayout();
             foreach (var panel in sheet.CuttedPanels)
             {
                 if (panel.Position != null)
                 {
                     var frame = new Frame
                     {
                         Padding = 0,
                         BorderColor = Color.Black,
                         BackgroundColor = Color.FromHex(GenerateColor()),
                         Content = new Label
                         {

                             TextColor = Color.White,
                             Text = $"{panel.Width} * {panel.Length} ID:{panel.Id}",
                             HorizontalTextAlignment = TextAlignment.Center,
                             VerticalTextAlignment = TextAlignment.Center
                         },



                     };
                     Rectangle rect = new Rectangle();
                     rect = new Rectangle(panel.Position.X * 1.2, panel.Position.Y * 1.2, panel.Width * 1.2, panel.Length * 1.2);

                     absolute.Children.Add(frame, rect);


                 }
             }
             Items.Add(absolute);

         }

and in Xaml as follow

         <ListView ItemsSource="{Binding Items}"
                   HasUnevenRows="True"
                   SeparatorColor="Black">
             <ListView.ItemTemplate>
                 <DataTemplate>
                     <ViewCell>
                         <ContentView Content="{Binding .}" BackgroundColor="White" />
                     </ViewCell>
                 </DataTemplate>
             </ListView.ItemTemplate>
         </ListView>

but now I want to use all using xaml no code behind so i tried to do nested list

         <CollectionView ItemsSource="{Binding Items}">
             <CollectionView.ItemTemplate>
                 <DataTemplate>
                     <AbsoluteLayout VerticalOptions="FillAndExpand">

                         <ListView x:Name="collection" ItemsSource="{Binding CuttedPanels}"
                                   VerticalOptions="FillAndExpand"
                                   HasUnevenRows="True">
                             <ListView.ItemTemplate>
                                 <DataTemplate>
                                     <ViewCell>

                                         <Frame Padding="0" 
                                                BackgroundColor="{Binding Color, Converter={converter:StringToColorConverter}}"
                                                AbsoluteLayout.LayoutBounds="{Binding .,Converter={converter:BoundsToRectangleConverter}}"
                                                AbsoluteLayout.LayoutFlags="None"
                                        BorderColor="Black">
                                                 <Label Text="{Binding Title}" TextColor="White"
                                            HorizontalTextAlignment="Center"
                                            VerticalTextAlignment="Center" />
                                             </Frame>

                                     </ViewCell>
                                 </DataTemplate>
                             </ListView.ItemTemplate>
                         </ListView>
                     </AbsoluteLayout>

                 </DataTemplate>
             </CollectionView.ItemTemplate>
         </CollectionView>

and the value converter to use for bounds

         if (value != null && value is Box box)
             return new Rectangle(box.Position.X * 1.2, box.Position.Y * 1.2, box.Width * 1.2, box.Length * 1.2);
         else
             return new Rectangle(0, 0, 0, 0);

but can not get the same behave as before

dotnet-xamarinformsdotnet-xamarinforms-xaml
· 1
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

You can add a breakpoint to the return new Rectangle(box.Position.X * 1.2, box.Position.Y * 1.2, box.Width * 1.2, box.Length * 1.2); this line in the value converter, check value of the box.Position and box.Length and box.Width. If this value is the same as code behind.

And please do not use nested listview in the CollectionView, it will cause focus conflict.

1 Vote 1 ·

1 Answer

ShereifAwad-5223 avatar image
0 Votes"
ShereifAwad-5223 answered ·
         <CollectionView x:Name="collection" ItemsSource="{Binding Items}" AbsoluteLayout.LayoutBounds="0,0,1,1"
                         AbsoluteLayout.LayoutFlags="All">
             <CollectionView.ItemTemplate>
                 <DataTemplate>
                     <AbsoluteLayout BindableLayout.ItemsSource="{Binding CuttedPanels}"
                                   VerticalOptions="FillAndExpand">
                         <BindableLayout.ItemTemplate>
                             <DataTemplate>

                                 <Frame Padding="0" 
                                                BackgroundColor="{Binding Color, Converter={converter:StringToColorConverter}}"
                                                AbsoluteLayout.LayoutBounds="{Binding .,Converter={converter:BoundsToRectangleConverter}}"
                                                AbsoluteLayout.LayoutFlags="None"
                                        BorderColor="Black">
                                     <Label Text="{Binding Title}" TextColor="White"
                                            HorizontalTextAlignment="Center"
                                            VerticalTextAlignment="Center" />
                                 </Frame>

                             </DataTemplate>
                         </BindableLayout.ItemTemplate>
                     </AbsoluteLayout>
                 </DataTemplate>
             </CollectionView.ItemTemplate>
         </CollectionView>
·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.