1 回答

TA贡献1820条经验 获得超10个赞
您可以自己滚动,但其他人已经为您完成了所有艰苦的工作。看看Xfx.Controls库。该XfxEntry看起来是你在寻找什么。您需要做的就是:
获取nuget 包,并将其安装在您的主项目和平台项目中。
确保在 Android 和 iOS 项目中初始化库。
在将要使用它的 xaml 页面的顶部,使用类似xmlns:xfx="clr-namespace:Xfx;assembly=Xfx.Controls".
使用控件,例如:
<xfx:XfxEntry Placeholder="Email"
Text="{Binding Email}" />
之后,您需要创建自己的自定义控件并将控件放入其中。要获得圆角,您需要从框架继承控件。这可能看起来像
<Frame x:Class="App1.MyCustomEntry"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:xfx="clr-namespace:Xfx;assembly=Xfx.Controls"
BorderColor="LightBlue"
CornerRadius="15" HorizontalOptions="FillAndExpand">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="8*" />
</Grid.ColumnDefinitions>
<Image Grid.Column="0" Source="email.png" />
<xfx:XfxEntry Grid.Column="1" Placeholder="Email*" />
</Grid>
注意BorderColor和CornerRadius属性。此外,如果您只是添加一个新的内容视图,则需要更改文件隐藏代码以继承 Frame: public partial class MyCustomEntry : Frame。
从那里,将控件插入页面很简单:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:App1"
x:Class="App1.MainPage">
<local:MyCustomEntry VerticalOptions="Center" HorizontalOptions="Center" />
</ContentPage>
这应该给你类似的东西:
您可以根据需要调整布局选项。
- 1 回答
- 0 关注
- 144 浏览
添加回答
举报