【发布时间】:2015-06-02 16:07:14
【问题描述】:
我正在尝试使用按钮在 Windows 商店应用程序中生成文本框,以便生成的每个新文本框(在从文本框恢复其值之后)位于前一个文本框的下方
我试过了
private void addBtn(object sender, RoutedEventArgs {
int t = 100;
TextBlock myTextBlock = new TextBlock();
myGrid.Children.Add(myTextBox);
myTextBlock.Text = taskTb.Text;
myTextBlock.Width = 300;
myTextBlock.Height = 300;
myTextBlock.FontSize = 25;
myTextBox.Margin = new Thickness(20,t,100,100);
t = t + 100;
}
但它不起作用,我在这里缺少什么?
【问题讨论】:
-
这有什么问题?
-
文本框位于其他人之上
-
您是否考虑过将它们放在
<StackPanel>或类似名称中? -
只需将
myGrid换成您的 StackPanel... -
停止。马上停下来。扔掉你迄今为止所做的一切。去了解 MVVM 的工作原理。现在重新开始,尝试通过代码添加 UI 元素所花费的时间很少。
标签: c# layout grid windows-store-apps