2
用戶可以從1-8位玩家中進行選擇,在下一頁我希望他爲每位玩家輸入名字。我怎樣才能使文本框取決於他們的選擇。 例如,他們選擇4,我想顯示四個文本框,以便他們可以放四個名字。如何根據用戶的選擇顯示特定數量的文本框?
用戶可以從1-8位玩家中進行選擇,在下一頁我希望他爲每位玩家輸入名字。我怎樣才能使文本框取決於他們的選擇。 例如,他們選擇4,我想顯示四個文本框,以便他們可以放四個名字。如何根據用戶的選擇顯示特定數量的文本框?
您將變量(玩家人數)過濾到下一頁。獲取變量後,只需將許多項目添加到您的收藏中。然後顯示你的收藏。
Page1.xaml.cs
// then you navigate like this (From Page1)
int number_of_players = 4;
Frame.Navigate(typeof(Page2), number_of_players);
Page2.xaml.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>