如何根据用户的选择显示特定数量的文本框
本文关键字:文本 显示 何根 用户 选择 | 更新日期: 2023-09-27 18:31:23
用户可以从1-8名球员中进行选择,在下一页,我希望他为每个球员命名。我如何根据他们的选择制作文本框。例如,他们选择 4,我想显示四个文本框,以便他们可以输入四个名称。
您将变量(玩家数量)转到下一页。 获取变量后,只需将那么多项目添加到您的集合中。 然后显示您的收藏集。
第 1.xaml 页.cs
// then you navigate like this (From Page1)
int number_of_players = 4;
Frame.Navigate(typeof(Page2), number_of_players);
第 2 页.cs
int number_of_players = 0;
// and in target Page you retrive the information:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
// get the number of players passed
number_of_players = e.Parameter as int;
}
// add in the correct number of players into the observable collection
private void Page_Loaded(object sender, RoutedEventArgs e)
{
ObservableCollection<sample_model> my_list = new ObservableCollection<sample_model>();
for (int i = 0; i < number_of_players; i++)
{
// where sample_model is a model of a player
my_list.Add(new sample_model("player name"));
}
this.myListView.ItemsSource = my_list;
}
<ListView x:Name="myListView">
<ListView.ItemTemplate>
<DataTemplate>
<Border BorderThickness="1" BorderBrush="Red">
<TextBlock Text="{Binding PlayerName}" Width="200" Height="200"></TextBlock>
</Border>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>