2016-07-20 46 views
0

虽然我在代码中设置的文本根本没有显示在标签上,但我试图在Xamarin表单中实现最基本的数据绑定形式。任何指针都会很棒。基本数据绑定(Xamarin Forms)

CS

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using Xamarin.Forms; 

namespace XamarinOuderportaal 
{ 
    public partial class LoginPage : ContentPage 
    { 
     public string UsernamePlaceHolder { get; set; } 
     public string PasswordPlaceHolder { get; set; } 

     public LoginPage() 
     { 
      this.UsernamePlaceHolder = "gebruikersnaam"; 
      this.PasswordPlaceHolder = "wachtwoord"; 
      InitializeComponent(); 
     } 
    } 
} 

XAML

<?xml version="1.0" encoding="utf-8" ?> 
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
      xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
      xmlns:local="clr-namespace:XamarinOuderportaal" 
      x:Class="XamarinOuderportaal.LoginPage"> 

    <StackLayout VerticalOptions="Center" HorizontalOptions="Fill" Spacing="20" Padding="20"> 
    <Entry Placeholder="This is the placeholder" HorizontalOptions="Fill" IsVisible="{Binding ShouldDisplayUrl}"/> 
    <Entry Placeholder="{Binding UsernamePlaceHolder}" HorizontalOptions="Fill"/> 
    <Entry Placeholder="{Binding PasswordPlaceHolder}" HorizontalOptions="Fill" IsPassword="true"/> 
    <Button Text="test 2" HorizontalOptions="Fill"/> 
    </StackLayout> 
</ContentPage> 

回答

0

绑定寻求在源对象的实例,所以性能一定不能是静态的。

如果你想使用静态绑定,则必须使用静态扩展:

<Entry Placeholder="{x:Static local:LoginPage.UsernamePlaceHolder}" HorizontalOptions="Fill"/> 

编辑:您已编辑的问题,并去掉了“静态”的定义,所以现在的代码必须工作。

+0

让我改变这一点。我现在只是在尝试一些东西。我更喜欢UsernamePlaceHolder和PasswordPlaceHolder不是静态的。感谢您快速回答btw。 –

+0

但你试过了吗?该属性不是静态的,它必须工作。 – Gusman

+0

如果我用你的行与一个静态变量或我在我的代码中的文本是根本不显示。如果我使用你的行与一个正常的变量应用程序崩溃。 –