无法使用 FindbyName<EntryCell>("txtCell") 在运行时更改 entrycell 值
Can't change entrycell value at runtime using FindbyName<EntryCell>("txtCell")
嘿,美好的一天,我真的很难在 运行 时尝试更改 entrycell 的值,我的代码是这样的:
reg.xaml
<TableSection Title="CREDENTIAL">
<EntryCell Label="Username:" Text="09068100820" Keyboard="Text" />
<EntryCell Label="Password:" x:Name="TxtPassword" Keyboard="Text" />
<EntryCell Label="Ref Code:" x:Name="TxtRefCodes" Keyboard="Text" />
<ViewCell>
<ContentView Padding="0,0">
<ContentView.Padding>
<OnPlatform x:TypeArguments="Thickness" iOS="10,0" WinPhone="0,15,0,0" />
</ContentView.Padding>
<ContentView.Content>
<Button x:Name="BntRegz" Clicked="BntRegz_OnClicked" BackgroundColor="#fd6d6d" Text="SUBMIT" TextColor="White"/>
</ContentView.Content>
</ContentView>
</ViewCell>
</TableSection>
reg.xaml.cs
private void BntRegz_OnClicked(object sender, EventArgs e)
{
var txt = this.FindByName<EntryCell>("TxtPassword");
txt.Text = "Test This";
}
非常感谢。
您的代码是正确的,但 Placeholder
仅在 EntryCell
为空时显示。
示例:
private void BntRegz_OnClicked(object sender, EventArgs e)
{
var txt = this.FindByName<EntryCell>("TxtRefCodes");
if (string.IsNullOrEmpty(txt.Placeholder))
{
txt.Placeholder = "EntryCell is Empty";
}
else
{
txt.Text = "Overwrite value entered by user";
}
}
空 TxtRefCodes
条目和用户单击提交,显示 Placeholder
:
用户在 TxtRefCodes
中输入文本:
用户点击提交,他的条目被覆盖:
嘿,美好的一天,我真的很难在 运行 时尝试更改 entrycell 的值,我的代码是这样的:
reg.xaml
<TableSection Title="CREDENTIAL">
<EntryCell Label="Username:" Text="09068100820" Keyboard="Text" />
<EntryCell Label="Password:" x:Name="TxtPassword" Keyboard="Text" />
<EntryCell Label="Ref Code:" x:Name="TxtRefCodes" Keyboard="Text" />
<ViewCell>
<ContentView Padding="0,0">
<ContentView.Padding>
<OnPlatform x:TypeArguments="Thickness" iOS="10,0" WinPhone="0,15,0,0" />
</ContentView.Padding>
<ContentView.Content>
<Button x:Name="BntRegz" Clicked="BntRegz_OnClicked" BackgroundColor="#fd6d6d" Text="SUBMIT" TextColor="White"/>
</ContentView.Content>
</ContentView>
</ViewCell>
</TableSection>
reg.xaml.cs
private void BntRegz_OnClicked(object sender, EventArgs e)
{
var txt = this.FindByName<EntryCell>("TxtPassword");
txt.Text = "Test This";
}
非常感谢。
您的代码是正确的,但 Placeholder
仅在 EntryCell
为空时显示。
示例:
private void BntRegz_OnClicked(object sender, EventArgs e)
{
var txt = this.FindByName<EntryCell>("TxtRefCodes");
if (string.IsNullOrEmpty(txt.Placeholder))
{
txt.Placeholder = "EntryCell is Empty";
}
else
{
txt.Text = "Overwrite value entered by user";
}
}
空 TxtRefCodes
条目和用户单击提交,显示 Placeholder
:
用户在 TxtRefCodes
中输入文本:
用户点击提交,他的条目被覆盖: