【问题标题】:insert Icon in a entry (xamarin) at the begging of the text在文本开头的条目(xamarin)中插入图标
【发布时间】:2022-07-28 04:57:25
【问题描述】:

我只是想把图标放在Entry的乞求上,没有办法,我已经阅读了,我不能,请我需要任何帮助 在这里,您有部分代码,我想在其中插入 ico

<ContentPage.Content>
    <Grid RowSpacing="{OnPlatform iOS=25,Android=20}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>        
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
             <ColumnDefinition/>
         </Grid.ColumnDefinitions>
    
        <StackLayout Grid.Row="3" HorizontalOptions="Center"
              WidthRequest="{OnPlatform iOS=300,Android=300}"
              Orientation="Vertical">
             <!-- Here where i insert the image -->
                <Image Grid.Column="1" Source="userImage.png"></Image>
                <Label 
                    Text="Usuario"
                    FontSize="{OnPlatform Android=13}"
                    TextColor="Black"
                />
                
                <Frame 
                    HasShadow="{OnPlatform Android=true, iOS=false}"
                    Padding="{OnPlatform Android=6,iOS=0}"
                    CornerRadius="{OnPlatform Android=7}">                   

                    <Entry                              
                      
                       Placeholder="Usuario" 
                       ClearButtonVisibility="WhileEditing"
                       MaxLength="25"
                       FontSize="{OnPlatform Android=15,iOS=16}"                       
                       TextColor="Blue" 
                       x:Name="txtUser">                        
                    </Entry>
                </Frame>
            </StackLayout>

【问题讨论】:

  • 你有什么问题?
  • 它显示在顶部的图标,我需要它与左侧的Entry。
  • 您正在使用垂直 StackLayout。如果希望图像与 Entry 水平对齐,则需要使用 Horizo​​ntal StackLayout
  • 欢迎。你应该看看How to Ask 和tour,如果你还没有这样做的话。也看看minimal reproducible example。这是您在提问时应牢记的一般信息。

标签: c# android xamarin mobile icons


【解决方案1】:

您似乎非常随意地使用 Grids 和 Stacklayouts。 您的问题确实来自您试图左对齐垂直 StackLayout 中的元素。只需将其放在水平 StackLayout 中即可解决您的问题。

<StackLayout>
    <StackLayout HorizontalOptions="Center"
                 WidthRequest="{OnPlatform iOS=300,Android=300}"
                 Orientation="Horizontal">
        <Image Grid.Column="1" 
               Source="userImage.png"/>
        <Label Text="Usuario"
                FontSize="{OnPlatform Android=13}"
                TextColor="Black" />
    </StackLayout>
    <Frame HasShadow="{OnPlatform Android=true, iOS=false}"
           Padding="{OnPlatform Android=6,iOS=0}"
           CornerRadius="{OnPlatform Android=7}">
        <Entry Placeholder="Usuario" 
               ClearButtonVisibility="WhileEditing"
               MaxLength="25"
               FontSize="{OnPlatform Android=15,iOS=16}"
               TextColor="Blue" 
               x:Name="txtUser" />
    </Frame>
</StackLayout>

当您在不是网格直接子级的 xaml 元素中定义“Grid.Row”或“Grid.Column”时要小心。在您的示例中,将网格列分配给图像元素不起作用,因为它是 StackLayout 的子元素而不是 Grid 这不会将元素分配给网格的任何行或列,因为它不是它的子元素。您可以查看 Xamarin 的 Grid Control 文档以获取更多信息。

【讨论】:

    猜你喜欢
    • 2020-02-04
    • 2014-11-19
    • 1970-01-01
    • 2012-03-20
    • 1970-01-01
    • 1970-01-01
    • 2011-01-03
    • 1970-01-01
    • 2011-05-04
    相关资源
    最近更新 更多