Skip to main content

Open-WebUI-Functions is here! New Pipelines, Filters, and more. Learn more

Custom Settings Container

Container

Here I have written a container where you can add any elements. The design is written to look like the button. The container with a switch looks like this:

custom-container

Key features

  • Icon awareness ensures the text region shifts automatically when an icon is provided.
  • Template bindings expose the inner content via ContentPresenter, so the control stays flexible.
  • The IsIconVisible flag keeps layouts compact when you omit an icon.

Here is the corresponding code for it:

How to use

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:fluent="http://www.aathifmahir.com/dotnet/2022/maui/icons"
xmlns:elements="using:App.Elements">
<Grid>
<elements:Container x:Name="Container"
IconSource="{fluent:Fluent Settings48, IconColor={AppThemeBinding Light={StaticResource Black}, Dark={StaticResource White}}}"
Text="Settings">
<Switch x:Name="Switch" IsToggled="True" />
</elements:Container>
</Grid>
</ContentPage>

NuGet Packages

Implementation notes

  • Expose additional bindable properties (for example IconSource or Text) through partial classes when you need to react in XAML.
  • Wrap the control in ContentPresenter-based templates if you plan to host it inside a list—this keeps virtualization efficient.
  • When hosting input controls, set HorizontalOptions="Fill" on the child to ensure the grid column expands correctly.