1 回答

TA貢獻1876條經驗 獲得超5個贊
您可以使用數據綁定來設置和獲取條目的文本。
在 xaml 中
<StackLayout>
<Button Text="GetEntryTemplate" Clicked="Button_Clicked"/>
<ListView x:Name="listView">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Entry TextColor="Black" Text="{Binding Content,Mode=TwoWay}"/>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
在你的代碼后面
創建一個模式(例如我的模型稱為數據)
public class Data
{
public string Content { get; set; }
}
并在 contentPage
public partial class MainPage : ContentPage
{
public ObservableCollection<Data> MySource { get; set; }
public MainPage()
{
InitializeComponent();
BindingContext = this;
MySource = new ObservableCollection<Data>()
{
new Data() {Content="Entry_1" },
};
listView.ItemsSource = MySource;
}
private void Button_Clicked(object sender, EventArgs e)
{
DisplayAlert("title", MySource[0].Content, "cancel");
}
}
https://i.stack.imgur.com/DKzMR.gif
- 1 回答
- 0 關注
- 95 瀏覽
添加回答
舉報