创建MAUI向导控件

huangapple go评论62阅读模式
英文:

Creating MAUI wizard control

问题

我正在创建一个 MAUI 中的向导控件。其中一个屏幕如下所示:

<?xml version="1.0" encoding="utf-8" ?>
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:helpers="clr-namespace:TimeApp.Helpers"
             x:Class="TimeApp.Controls.Wizard.Steps.SetupWizardWelcomeView">
    <StackLayout VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
        <VerticalStackLayout VerticalOptions="Start">
            <Label 
                Text="¡ Bienvenido a su enrolamiento !"
                HorizontalOptions="Center" />
        </VerticalStackLayout>
        <StackLayout Padding="0, 20, 0, 20" VerticalOptions="CenterAndExpand">
            <Label 
                Text="Por medio de este asistente, podr&#225; darse de alta en el sistema de control de asistencia de su empresa" />
        </StackLayout>
        <VerticalStackLayout VerticalOptions="End">
            <Grid ColumnDefinitions="*, *" BackgroundColor="red">
                <HorizontalStackLayout HorizontalOptions="FillAndExpand">
                    <Button Margin="10, 0, 10, 0" Text="Anterior" Grid.Column="0" HorizontalOptions="Start">
                        <Button.ImageSource>
                            <FontImageSource
                                FontFamily="FontAwesomeSolid"
                                Glyph="{x:Static helpers:FontAwesomeIcons.Previous}"
                                Color="DodgerBlue"
                                Size="24"/>
                        </Button.ImageSource>
                    </Button>
                    <Button Margin="10, 0, 10, 0" Grid.Column="1" HorizontalOptions="End">
                        <Button.ImageSource>
                            <FontImageSource
                                FontFamily="FontAwesomeSolid"
                                Glyph="{x:Static helpers:FontAwesomeIcons.Next}"
                                Color="DodgerBlue"
                                Size="24"/>
                        </Button.ImageSource>
                        <Button.Text>Siguente</Button.Text>
                    </Button>
                </HorizontalStackLayout>
            </Grid>
        </VerticalStackLayout>
    </StackLayout>
</ContentView>

首先,我需要将按钮放在页面底部,其次,将 FontAwesomeIcons.Next 图标放在按钮标签的右侧。如何实现呢?我已经花了好几个小时尝试,但没有成功。

英文:

I am creating a wizard control in MAUI. On of the screens is this:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt;
&lt;ContentView xmlns=&quot;http://schemas.microsoft.com/dotnet/2021/maui&quot;
xmlns:x=&quot;http://schemas.microsoft.com/winfx/2009/xaml&quot;
xmlns:helpers=&quot;clr-namespace:TimeApp.Helpers&quot;
x:Class=&quot;TimeApp.Controls.Wizard.Steps.SetupWizardWelcomeView&quot;&gt;
&lt;StackLayout VerticalOptions=&quot;FillAndExpand&quot; HorizontalOptions=&quot;FillAndExpand&quot;&gt;
&lt;VerticalStackLayout VerticalOptions=&quot;Start&quot;&gt;
&lt;Label 
Text=&quot;&#161; Bienvenido a su enrolamiento !&quot;
HorizontalOptions=&quot;Center&quot; /&gt;
&lt;/VerticalStackLayout&gt;
&lt;StackLayout Padding=&quot;0, 20, 0, 20&quot; VerticalOptions=&quot;CenterAndExpand&quot;&gt;
&lt;Label 
Text=&quot;Por medio de este asistente, podr&#225; darse de alta en el sistema de control de asistencia de su empresa&quot; /&gt;
&lt;/StackLayout&gt;
&lt;VerticalStackLayout VerticalOptions=&quot;End&quot;&gt;
&lt;Grid ColumnDefinitions=&quot;*, *&quot; BackgroundColor=&quot;red&quot;&gt;
&lt;HorizontalStackLayout HorizontalOptions=&quot;FillAndExpand&quot;&gt;
&lt;Button Margin=&quot;10, 0, 10, 0&quot; Text=&quot;Anterior&quot; Grid.Column=&quot;0&quot; HorizontalOptions=&quot;Start&quot;&gt;
&lt;Button.ImageSource&gt;
&lt;FontImageSource
FontFamily=&quot;FontAwesomeSolid&quot;
Glyph=&quot;{x:Static helpers:FontAwesomeIcons.Previous}&quot;
Color=&quot;DodgerBlue&quot;
Size=&quot;24&quot;/&gt;
&lt;/Button.ImageSource&gt;
&lt;/Button&gt;
&lt;Button Margin=&quot;10, 0, 10, 0&quot; Grid.Column=&quot;1&quot; HorizontalOptions=&quot;End&quot;&gt;
&lt;Button.ImageSource&gt;
&lt;FontImageSource
FontFamily=&quot;FontAwesomeSolid&quot;
Glyph=&quot;{x:Static helpers:FontAwesomeIcons.Next}&quot;
Color=&quot;DodgerBlue&quot;
Size=&quot;24&quot;/&gt;
&lt;/Button.ImageSource&gt;
&lt;Button.Text&gt;Siguente&lt;/Button.Text&gt;
&lt;/Button&gt;
&lt;/HorizontalStackLayout&gt;
&lt;/Grid&gt;
&lt;/VerticalStackLayout&gt;
&lt;/StackLayout&gt;
&lt;/ContentView&gt;

I am not getting the page to look how I need.

First, I need the buttons to be placed at the bottom of the page and second, to place the FontAwesomeIcons.Next icon to the right of the button label.

How can I do that? I have already spent several hours trying to do this but no avail.

答案1

得分: 0

Sure, here's the translated content:

将FontAwesomeIcons.Next图标放置在按钮标签的右侧。

要实现这一点,您可以使用ContentLayout属性,该属性定义了控制按钮图像位置以及按钮图像和文本之间间距的对象。

所以,如果您想将图标放在文本的右侧,请尝试以下操作:

<Button WidthRequest="200" Margin="10, 0, 10, 0" Text="Anterior" ContentLayout="Right,1">

其中的 "1" 表示文本和图像之间的间距。

要将按钮放置在底部,正如@Jason所说,使用网格可以实现这一点,尽管您使用了自定义控件。解决方案类似于以下内容:

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             ...>

    <Grid RowDefinitions="*,Auto">
        <VerticalStackLayout 
            Spacing="25"
            Padding="30,0"
            VerticalOptions="Center">
            ......
        </VerticalStackLayout>
        <local:CustomControl Grid.Row="1"/> // 您的自定义控件/ContentView
    </Grid>

</ContentPage>

希望能够起作用。

英文:

> to place the FontAwesomeIcons.Next icon to the right of the button label.

To achieve this, you may use ContentLayout property which defines the object that controls the position of the button image and the spacing between the button's image and text.

So you want to place the icon the right of the text, try the following:

&lt;Button WidthRequest=&quot;200&quot; Margin=&quot;10, 0, 10, 0&quot; Text=&quot;Anterior&quot; ContentLayout=&quot;Right,1&quot;&gt;

The "1" stands for the spacing between the text and the image.

To place the button at the bottom, just as @Jason said, using a grid can achieve this, though you use a custom control. The solution is the similar.

&lt;ContentPage xmlns=&quot;http://schemas.microsoft.com/dotnet/2021/maui&quot;
...
&gt;
&lt;Grid RowDefinitions=&quot;*,Auto&quot;&gt;
&lt;VerticalStackLayout 
Spacing=&quot;25&quot;
Padding=&quot;30,0&quot;
VerticalOptions=&quot;Center&quot;&gt;
......
&lt;/VerticalStackLayout&gt;
&lt;local:CustomControl Grid.Row=&quot;1&quot;/&gt; // your custom control/ContentView
&lt;/Grid&gt;
&lt;/ContentPage&gt;

Hope it works

huangapple
  • 本文由 发表于 2023年6月13日 08:05:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/76460958.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定