使用FindbyName <entrycell>(&#34; txtCell&#34;)无法在运行时更改输入单元格值

时间:2016-07-18 03:00:56

标签: xaml xamarin xamarin.forms xamarin-studio

嘿,好日子我真的很难在运行时尝试更改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";
        }

提前多多感谢。 enter image description here

1 个答案:

答案 0 :(得分:0)

您的代码是正确的,但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

enter image description here

用户将文字输入TxtRefCodes

enter image description here

用户点击“提交”并覆盖其条目:

enter image description here