【发布时间】:2016-09-22 12:20:39
【问题描述】:
我想将插入的数值从我正在插入值的页面传递到另一个页面列表并使用新值更新 ListView。
这是我的 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());
}
和带有 ListView 的 CardsPage xaml:
<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>
如何将插入的Entry值从页面传递到另一个类List并更新ListView内容?
【问题讨论】:
-
我不完全确定你在这里做什么,但它不只是简单地将
Entry的Text属性绑定到Number吗?<Entry x:Name="CardNr" Text="{Binding Number}" Completed="Entry_Completed" Keyboard="Numeric" /> -
@GeraldVersluis 是的,但是“Number”在另一个类中,所以如果我没有在任何地方声明我的 Cards 类,我该如何绑定?
-
啊,我明白了,你使用任何 MVVM 框架之类的吗?您现在如何从一个页面导航到另一个页面?请使用代码更新您的问题。
-
@GeraldVersluis 更新
标签: c# list xaml listview xamarin.forms