0
我想從插入值的頁面向其他頁面列表傳遞插入的數值,並使用新值更新ListView。Xamarin形式如何將Entry值從一個類傳遞到另一個類List?
這裏是我的AddCardPage XAML:
<Entry x:Name="CardNr" Text="" Completed="Entry_Completed" Keyboard="Numeric" />
這裏是AddCardPage xaml.cs方法:
void Entry_Completed(object sender, EventArgs e)
{
var text = ((Entry)sender).Text; //cast sender to access the properties of the Entry
new Cards { Number = Convert.ToInt64(text) };
}
這裏就是我已經宣佈了一些數據我CardsPage類:
public CardsPage()
{
InitializeComponent();
base.Title = "Cards";
List<Cards> cardsList = new List<Cards>()
{
new Cards { Number=1234567891234567, Name="dsffds M", ExpDate="17/08", Security=123 },
new Cards { Number=9934567813535135, Name="Jason T", ExpDate="16/08", Security=132 },
new Cards { Number=4468468484864567, Name="Carl S", ExpDate="17/01", Security=987 },
};
listView.ItemsSource = cardsList;
AddCard.GestureRecognizers.Add(new TapGestureRecognizer
{
Command = new Command(() => OnLabelClicked()),
});
}
private void OnLabelClicked()
{
Navigation.PushAsync(new AddCardPage());
}
and CardsPage xaml with ListView:
<ListView x:Name="listView">
<ListView.Footer>
<StackLayout Padding="5,5" Orientation="Horizontal" >
<Label x:Name="AddCard" Text="Add new Card" FontSize="15" />
</StackLayout>
</ListView.Footer>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Label Text="{Binding Number}" FontSize="15" />
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
如何將插入的條目值從頁面傳遞到另一個類列出並更新ListView內容?
我不能完全肯定的你在做什麼在這裏,但不是它只是單純的你'Entry'的'Text'屬性綁定到'Number'? ' –
@GeraldVersluis是的,但是「Number」在另一個類中,所以我怎樣綁定如果我沒有宣佈我的卡片課無處? – BinaryTie
啊我看,你使用任何MVVM框架或什麼?你現在如何從一個頁面導航到另一個頁面?請更新您的問題與代碼。 –