gpt4 book ai didi

ios - 如何在 Xamarin.Forms 中设置控件的宽度

转载 作者:技术小花猫 更新时间:2023-10-29 10:29:56 25 4
gpt4 key购买 nike

我尝试在 Xamarin.Forms for iPad 应用程序中调整我的文本框 [Entry] 控件的宽度和高度,但它没有使用 WidthRequest 属性设置宽度。

谁能帮我解决如何设置控件的宽度问题。

这是我使用 Grid 和 StackLayout 的 XAML 代码,但它们都不起作用。

<Grid VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" >
<Grid.RowDefinitions>
<RowDefinition Height="Auto" ></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="10"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>

<Image Grid.Row="0" Grid.Column="0" Source="loginlogo.png"></Image>
<StackLayout Grid.Row="1" Grid.Column="0">
<Entry Placeholder="Enter Username" WidthRequest="20"></Entry>
<Entry Placeholder="Enter Password" WidthRequest="20"></Entry>
<Button Text="Button 1"></Button>
</StackLayout>
</Grid>

还尝试了堆栈布局

<StackLayout Spacing="10">
<Entry x:Name="txtUserName" Placeholder="Enter Username" WidthRequest="2" HeightRequest="200"></Entry>
<Entry x:Name="txtPassword" Placeholder="Enter Password" WidthRequest="2" HeightRequest="200"></Entry>
<Button Text="Button 1"></Button></StackLayout>

最佳答案

请注意,您必须使用 WidthRequest 指定 Horizo​​ntalOptions 才能使其在 StackLayout 上工作,因为它将尝试自动展开默认情况下。

StackLayout 示例如下:-

        StackLayout objStackLayout = new StackLayout()
{
Spacing = 10
};
//
Entry objEntry1 = new Entry()
{
Placeholder = "Enter Username",
WidthRequest = 300,
HeightRequest = 200,
HorizontalOptions = LayoutOptions.Start
};
objStackLayout.Children.Add(objEntry1);
//
Entry objEntry2 = new Entry()
{
Placeholder = "Enter Password",
WidthRequest = 200,
HeightRequest = 200,
HorizontalOptions = LayoutOptions.Start
};
objStackLayout.Children.Add(objEntry2);
//
Button objButton1 = new Button()
{
Text = "Button1",
HorizontalOptions = LayoutOptions.Start
};
objStackLayout.Children.Add(objButton1);

关于ios - 如何在 Xamarin.Forms 中设置控件的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25663347/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com