c# - How do I add more fields/entries when a button is selected using xamarin?
问题描述
I'm creating a mobile app using Xamarin (C# and XAML) for the first time. I would like to add functionality to add another Entry when the user selects the "Add" button.
More specifically, when the button is clicked I want it to create 2 new Entry fields. They are different from each other, but the same 2 appear on the page just above the button. If this isn't possible with XAML and C#, is there a way the button could unhide hidden Entries when clicked?
Thanks in advance.
解决方案
“有没有一种方法可以在单击时取消隐藏隐藏的条目?”
是的,只需IsVisible
在 .. 上设置属性即可Entry
。简单示例:
<StackLayout Margin="0,50,0,0">
<Entry x:Name="entry1" Placeholder="Entry 1..." IsVisible="false" />
<Entry x:Name="entry2" Placeholder="Entry 2..." IsVisible="false" />
<Button Text="Add entries" Clicked="Button_Clicked" />
</StackLayout>
后面的代码:
void Button_Clicked(System.Object sender, System.EventArgs e)
{
entry1.IsVisible = true;
entry2.IsVisible = true;
}
推荐阅读
- php - PHP Laravel 会话闪烁警报消息未显示
- three.js - 在 Three.js 中为 glb 模型分配的纹理被反转并且仅使用 THREE.RepeatWrapping
- wordpress - 亚马逊网站条纹中的图像 src
- javascript - 字符串到 JS 对象数组
- r - 具有多个参数的映射,其中一个参数是常量(数据)
- java - Spring Boot JPQL 不适用于特定条件
- java - Spring Boot @RequestBody 不会完全复制参数
- python - 使用“pandas.read_csv”使得所有列 dtypes 都是“对象”python
- bash - Exif工具 | 返回移动文件的列表
- css - 我正在尝试覆盖“react-carousel-component”的 CSS 类,但在网站的不同部分