2016-07-20 17 views
0

私は自分のコードで設定したテキストがラベルに表示されていませんが、Xamarinフォームで最も基本的なデータバインディングを実現しようとしています。どのポインタも素晴らしいでしょう。基本的なデータバインディング(Xamarinフォーム)

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"/> 

EDITを:あなたは質問を編集し、「静的」の定義を削除し、そのコードが動作する必要がありました。

+0

を結合Xamarinの基本的なことを確認してください。私はこの時点で物事を試していただけだった。私はUsernamePlaceHolderとPasswordPlaceHolderが静的でないことを好みます。あなたのクイックアンサーbtwをありがとう。 –

+0

しかし、あなたはそれを試してみましたか?プロパティは静的ではないので動作する必要があります。 – Gusman

+0

静的変数を使用して行を使用する場合、またはコード内にある行は、単に表示されません。あなたの行を通常の変数で使用すると、アプリケーションがクラッシュします。 –

関連する問題