gpt4 book ai didi

c# - 在 TableView 中绑定(bind) TextCell

转载 作者:行者123 更新时间:2023-11-29 00:18:10 24 4
gpt4 key购买 nike

我已经使用字符串整数将详细信息传递给下一个Form,并将它们存储在类的中构造函数,现在如何将构造函数中的值(参数化值)绑定(bind)到 TableView 中的 TextCell

最初,这就是我启动另一个表单的方式。

await Navigation.PushAsync(new LoginSalesDetails(Usnmae, AgentNumber, AgentName, AgentPhone, AgentEmail, Agentrating)); 

这是我的类(class)代码:

public LoginSalesDetails(string Username, string AgentNo, string AgentName, string AgentPhone, string AgentEmail, int AgentRating)
{
InitializeComponent();



accountname_label.Text = AgentName;
agent_no_label.Text = AgentNo;
rating_label.Text = "" + AgentRating;
mobileno_label.Text = AgentPhone;
email_label.Text = AgentEmail;

Name_A(AgentName);


// DisplayAlert("Alert ", ""+AgentName, "OK");
}




public string Name_A(string a)
{


return a;
}

然后,这是由 TableViewTexCells 组成的 XAML 代码。

<TableView Intent="Form">
<TableView.Root>
<TableSection Title="Agent Sales Details">
<TextCell Text="Agent Number" Detail="{Binding Name_A}" />
<TextCell Text="Agent Rating " Detail="4" />
<TextCell Text="Agent Phone " Detail="0474774747475" />
<TextCell Text="Agent Email " Detail="huxy@gmail.com" />
</TableSection>
</TableView.Root>
</TableView>

编辑

我的 Class.cs 代码:

public partial class LoginSalesDetails : ContentPage
{
public string Name_A { get; set; }
public string Email_A { get; set;}
public string Phone_A { get; set;}
public string Rating_A { get; set;}
public string No_A { get; set;}

public LoginSalesDetails(string Username, string AgentNo, string AgentName, string AgentPhone, string AgentEmail, int AgentRating)
{
InitializeComponent();



accountname_label.Text = AgentName;
agent_no_label.Text = AgentNo;
rating_label.Text = "" + AgentRating;
mobileno_label.Text = AgentPhone;
email_label.Text = AgentEmail;

Name_A = AgentName;
Email_A = AgentEmail;
Phone_A = AgentPhone;
Rating_A = ""+ AgentRating;



// DisplayAlert("Alert ", ""+AgentName, "OK");
}


}

我的 XAML 代码:

<TableView Intent="Form">
<TableView.Root>
<TableSection Title="Agent Sales Details">
<TextCell Text="Agent Number" Detail="{Binding Name_A}" />
<TextCell Text="Agent Rating " Detail="{Binding Email_A}" />
<TextCell Text="Agent Phone " Detail="{Binding Phone_A}" />
<TextCell Text="Agent Email " Detail="huxy@gmail.com" />
</TableSection>
</TableView.Root>
</TableView>

最佳答案

您现在正尝试绑定(bind)到一个方法,这是不可能的。这应该始终对公共(public)属性(property)进行。例如,像这样更改您的代码:

public string Name_A { get; set; }

public LoginSalesDetails(string Username, string AgentNo, string AgentName, string AgentPhone, string AgentEmail, int AgentRating)
{
InitializeComponent();



accountname_label.Text = AgentName;
agent_no_label.Text = AgentNo;
rating_label.Text = "" + AgentRating;
mobileno_label.Text = AgentPhone;
email_label.Text = AgentEmail;

Name_A = AgentName;


// DisplayAlert("Alert ", ""+AgentName, "OK");
}

请注意,我删除了该方法,并将 Name_A 添加为属性。

此外,如果您还没有这样做,您需要将包含您的 TableView 的页面的 BindingContext 设置为 LoginSalesDetails< 的实例 对象。

关于c# - 在 TableView 中绑定(bind) TextCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44781624/

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