2016-09-23 14 views
1

C#で私のOnAppearing()メソッドの中に変数var wordsCount = App.words.Count.ToString();があります。 wordsCountの値をXAML側のcontentpageのtitleプロパティに渡すにはどうすればいいですか?そのページに行くたびにタイトルが更新されますか?種類の次のコードのように:あなたのページのオーバーライドOnAppearing()の背後にあるコードでxamarinフォームのXAML内でContentPage Titleを動的に変更する方法はありますか?

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
     xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
     x:Class="Japanese.PhrasesPage" 
     Title="wordsCount"> 
</ContentPage> 

答えて

2

Titleプロパティ設定:あなたはバインディングを使用したい場合

override void OnAppearing() 
{ 
    Title = wordsCount; 
} 

を、あなたはBindingContextを設定する必要がありますそして、あなたのフィールドパブリックプロパティを作る:

public class MyPage : ContentPage 
{ 
    public ContentPage() 
    { 
    BindingContext = this; 
    } 

    public string WordCount { get { return wordCount; }} 
} 

そして、XAMLで:

Title="{Binding WordCount}"

関連する問題