我想在Xamarin中向现有表单添加其他元素,并更改现有表单上的现有元素。以下是需要在按钮Name = "GenerateBtn"
:
Entry accNumber = new Entry()
{
Text = "number"
};
我可以专门添加到RelativeLayout还是StackLayout足够?这是xaml文件:
<StackLayout
x:name = "First"
VerticalOptions ="Center" HorizontalOptions="Center">
<Entry
Text="First name"/>
<Entry
Text="Last name"/>
<RelativeLayout
x:Name = "cardInfo"
VerticalOptions ="Center" HorizontalOptions="Center"
RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Y, Factor=0, Constant=220}"
HeightRequest="60"
RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=1}" >
<Button
x:Name = "Account"
Text="account"
Clicked="Handle_Clicked"
HeightRequest="50"
WidthRequest="120"
RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Y, Factor=0, Constant=5}"
RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=X, Factor=0, Constant=5}"/>
<Button
x:Name = "Btn2"
Text="button2"
Clicked="Handle_Clicked"
HeightRequest="50"
WidthRequest="120"
RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Y, Factor=0, Constant=5}"
RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width, Factor=0.5, Constant=5}" />
</RelativeLayout>
<Button
x:Name = "GenerateBtn"
Text="Generate"
Clicked="Handle_Clicked"/>
</StackLayout>
答案 0 :(得分:0)
您需要先将Button(Name = "GenerateBtn")
包裹在StackLayout
内,然后将Entry
作为子视图添加到Stacklayout中。
<StackLayout x:Name="stack" Orientation="Horizontal">
<Button x:Name = "GenerateBtn" Text="Generate"/>
</StackLayout>
stack.Children.Insert(0,new Entry { Text = "number" });