【发布时间】:2021-12-12 04:50:13
【问题描述】:
大家好,
我正在使用 C# 在 UWP 中做一个桌面应用程序。
我想根据用户输入创建 unknow 文本框。
例如,假设我在 Page1 上有 TextBox 和 OkButton,用户必须在文本框中输入数字,然后按下 OkButton。之后,应用程序将导航到另一个页面(我们称之为 Page 2),该页面将包含与用户输入一样多的文本框。
例如,用户在 Page1 上的 TextBox 中键入 5,然后按下按钮,应用程序将导航到 Page2,它将包含 5 个 TextBox准备好另一个输入
这是一个示例源代码
Page1.xaml
<Grid>
<TextBox x:Name="UserInput" Margin="558,459,557,459" Header="UserInput"/>
<Button x:Name="DoneButton" Height="29" Width="95" Margin="558,565,0,0" VerticalAlignment="Top" Content="Done" Click="DoneButton_Click"/> </Grid>
Page1.xaml.cs
public sealed partial class Page1 : Page
{
public Page1()
{
this.InitializeComponent();
}
private void DoneButton_Click(object sender, RoutedEventArgs e)
{
(App.Current as App).UserInput = Convert.ToInt32( UserInput.Text); // this will store userinput data in the global app variable
// variable so I can work with that later
this.Frame.Navigate(typeof(Page2));
}
Page2.xaml
<Grid>
<TextBlock Text="Here I want to create text boxes based on user input" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="30"/>
</Grid>
Page2.xaml.cs
public sealed partial class Page2 : Page
{
public Page2()
{
this.InitializeComponent();
}
public int UserInput = (App.Current as App).UserInput; //storing global app variable to work with it later
//here I want to crate multiple text boxes
}
感谢你们宝贵的时间和答案。 :)
【问题讨论】:
标签: c# xaml uwp textbox user-input