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

Chapter 6 Creating Our Own Layout

This method allows the caller to pass a placeholder that will be removed from the PlaceholderGrid. This is useful for when dealing with a widget being added to a specific position.

public void AddColumn(ColumnDefinition columnDefinition)

{

PlaceholderGrid.ColumnDefinitions.Add(columnDefinition);

WidgetGrid.ColumnDefinitions.Add(columnDefinition);

}

This method allows for the board’s columns to be defined on both the

PlaceholderGrid and WidgetGrid.

public void AddRow(RowDefinition rowDefinition)

{

PlaceholderGrid.RowDefinitions.Add(rowDefinition);

WidgetGrid.RowDefinitions.Add(rowDefinition);

}

This method allows for the board’s rows to be defined on both the

PlaceholderGrid and WidgetGrid.

public IReadOnlyList<Placeholder> Placeholders => PlaceholderGrid.Children.OfType<Placeholder>().ToList();

This property provides all children from the PlaceholderGrid that are of type Placeholder. This is to allow for determining which placeholder needs to be removed when adding a widget.

FixedLayoutManager

The final part for you to create is the FixedLayoutManager class. This will provide the logic to

•\ Accept the number of rows and columns for a board.

177

Chapter 6 Creating Our Own Layout

•\

Provide tap/click support through a command.

•\

Build the board layout.

•\

Set the correct row/column position for each widget.

Create the file and then you can work through adding each of the above pieces of functionality. Let’s add a new class file and call it FixedLayoutManager.cs. Add the following content:

namespace WidgetBoard.Layouts;

public class FixedLayoutManager

{

}

To start, you are going to want to add the following using statements:

using System.Windows.Input; using WidgetBoard.Controls;

And also make your class inherit from BindableObject and implement your ILayoutManager interface. Your class should now look as follows:

using System.Windows.Input; using WidgetBoard.Controls;

namespace WidgetBoard.Layouts;

public class FixedLayoutManager : BindableObject, ILayoutManager

{

}

The reason for inheriting from BindableObject is down to the fact that you need to add some bindable properties onto this class so that developers using this implementation can bind values to the properties.

178