c# - 如何从上一页的文本框中获取变量到下一页?
问题描述
我正在尝试创建一个搜索框,引导到另一个页面来执行搜索。例如在 Inquirypage 中搜索 --> 在 Listpage 中获取结果。我如何从查询页面获取值到列表页面,因为它们不在同一个类中。我可以得到一些见解吗?谢谢
从第一页搜索按钮:
public async void FromBPSearchTap(object sender, EventArgs e)
{
var BPSearch = Customer.Text;
if (string.IsNullOrWhiteSpace(BPSearch))
{
BPSearch = string.Empty;
}
BPSearch = BPSearch.ToUpperInvariant();
}
解决方案
将字符串作为参数传递给下一页的构造函数。
示例代码如下:
在你的InquiryPage.xaml.cs
private async void FromBPSearchTap(object sender, System.EventArgs e)
{
//...
//your code with BPSearch
await Navigation.PushAsync(new ListPage(BPSearch));
}
在你的下一个ListPage.xaml.cs
string _searchText
public ListPage(string searchText)
{
InitializeComponent();
_searchText = searchText; //have your text in ListPage now
}
推荐阅读
- ios - UitableView 不滚动超过第一个单元格
- thorntail - What is the simplest way to add application users in a Thorntail WildFly server?
- unity3d - ML-AGENTS tensorflow 模型未在推理模式下运行
- c - How to change signal handler in child-process?
- cron - 本月第 n 个星期六的 Linux crontab
- android - 单击标记谷歌地图sdk后如何向下移动相机视图
- javascript - 如何使用 localStorage 缓存按钮结果?
- sql - Subselect, Group by and Having Count with criteria in hibernate
- typescript - How to create a factory object without violating OCP in Typescript
- c# - DinkToPdf Net Core 无法加载 DLL 文件