VB.NET, C#, PowerShellを使用しているエンジニアのためのサイト。
基本的な使用方法から開発で役立つTipsまで幅広く取り扱っています。
Update 2019/01/07
< Prev Tips
Next Tips>
Entryコントロールに入力されたテキストを取得するには、Text プロパティを使用します。
以下は、EntryのTextプロパティをLabelにバインディングして表示するXamlの例です。
<Entry x:Name="entry1" WidthRequest="100" />
<!-- Entryのテキストを表示 -->
<Label Text="{Binding Source={x:Reference entry1}, Path=Text}"
HorizontalOptions="Center"
VerticalOptions="CenterAndExpand" />
実行例を以下に示します。
次に、コードビハインドでの実装例を以下に示します。
画面には、Entry, Button, Labelを1つずつ配置し、ButtonがクリックされたらEntryの内容をLabelに表示します。
12行目のようにEntryのTextプロパティをLabelのTextプロパティに代入します。
<Entry x:Name="entry1" Text="Hello Xamarin" />
<Button x:Name="button1" Text="Get Text" />
<Label x:Name="label1" />
MainPage.xaml.cs
namespace entrySample02
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
button1.Clicked += (sender, e) =>
{
// Entryに入力されているテキストをLabelに表示
label1.Text = entry1.Text;
};
}
}
}
実行例を以下に示します。