[英]Xamarin: Get bound property of Entry.Text from event handler in code behind
[英]Get Entry.Text from Entry defined in xaml
試圖冷靜地寫作,因為我現在對 Xamarin 感到非常沮喪。 我有一個在 MainPage.xaml 中定義的條目。 它看起來像這樣:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:TestFood"
x:Class="TestFood.MainPage" BackgroundColor="CornflowerBlue">
<ContentPage.Content>
<StackLayout VerticalOptions="CenterAndExpand">
<Label HorizontalTextAlignment="Center" Text="EATH" TextColor="#FFFFFF" FontSize="64"/>
<StackLayout>
<Entry x:Name="budgetEntry" Placeholder="Budget" Keyboard="Numeric" HorizontalTextAlignment="Center" Margin="40,0"/>
<Button Margin="80,0" Text="Search Recipes" Clicked="Button_Clicked">SubmitButton</Button>
</StackLayout>
</StackLayout>
</ContentPage.Content>
我要做的就是從條目中獲取文本並在我的 MainPage.xaml.cs 中使用它。 鑒於 Xamarin 可能非常復雜,我該如何處理? 我看過 Binding 但文檔相當糟糕,並沒有真正讓你從任何地方開始。
任何分配了 Name 的元素都可以從后面的代碼中引用
var txt = budgetEntry.Text;
雖然可以從后面的代碼訪問Text
屬性,就像Jason在他的回答中提到的那樣,但我認為綁定似乎是一個更好,更可靠的選擇。
Xamarin本身發表的一篇有趣的文章很好地解釋了這一點。 您可以在這里閱讀: https : //blog.xamarin.com/introduction-to-data-binding/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.