Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
lawrence_shaun_introducing_net_maui_build_and_deploy_crosspl.pdf
Скачиваний:
36
Добавлен:
26.06.2023
Размер:
5.15 Mб
Скачать

Chapter 6 Creating Our Own Layout

tapGestureRecognizer.Tapped += TapGestureRecognizer_Tapped;

 

placeholder.GestureRecognizers.Add(tapGesture

 

Recognizer);

 

Board.AddPlaceholder(placeholder);

 

Grid.SetColumn(placeholder, column);

 

Grid.SetRow(placeholder, row);

}

 

}

 

In the above code, you

•\

Looped through the combinations of rows/columns

•\

Created a Placeholder control

•\

Set its position for use later

•\

Added a TapGestureRecognizer to handle user

 

interaction

•\

Added the Placeholder to the Board

•\

Positioned the Placeholder to the correct column and

 

row position

Setting the Correct Row/Column Position for Each Widget

The final part in building the board layout is to provide the method required by the ILayoutManager interface that your FixedLayoutManager is implementing. This method will

•\ Calculate the column/row value based on the position parameter passed in.

185

Chapter 6 Creating Our Own Layout

•\

Position the bindableObject parameter passed into the

 

calculated column and row position.

•\

Remove any existing Placeholder in the position.

public void SetPosition(BindableObject bindableObject, int position)

{

if (NumberOfColumns == 0)

{

return;

}

int column = position % NumberOfColumns; int row = position / NumberOfColumns;

Grid.SetColumn(bindableObject, column);

Grid.SetRow(bindableObject, row);

var placeholder = Board.Placeholders.Where(p => p.Position == position).FirstOrDefault();

if (placeholder is not null)

{

Board.RemovePlaceholder(placeholder);

}

}

Now that you have completed the work of providing a BoardLayout and managing its layout with your FixedLayoutManager class, you should go ahead and use it in your application.

186