在网格中动态创建文本框
这可能是骗子,但我找不到可以帮助我提供解决方案的信息。
我基本上有一个stackpanel,它的网格带有定义的行和列,我想在不同的行和列中动态创建一定的文本框,然后我可以用来与之交互。
到现在为止,我的解决方案是在WPF中逐一创建每个文本框,然后将所有这些文本框一个一个一个一个一个一个一个将它们添加到C#中的文本框列表中以与它们进行交互。但是我真的不相信这是一个干净的解决方案。
示例WPF
<TextBox x:Name="Std2018_01" Grid.Row="1" Grid.Column="1" Height="20" Width="50" TextAlignment="Center" BorderBrush="{x:Null}" TextChanged="Std2018_TextChanged"></TextBox>
<TextBox x:Name="Std2018_02" Grid.Row="2" Grid.Column="1" Height="20" Width="50" TextAlignment="Center" BorderBrush="{x:Null}" TextChanged="Std2018_TextChanged"></TextBox>
<TextBox x:Name="Std2018_03" Grid.Row="3" Grid.Column="1" Height="20" Width="50" TextAlignment="Center" BorderBrush="{x:Null}" TextChanged="Std2018_TextChanged"></TextBox>
C#将它们添加到列表中,
boxes2018.Add(Std2018_01);
boxes2018.Add(Std2018_02);
boxes2018.Add(Std2018_03);
必须有一种更好的方法来解决此问题。
This probably is a dupe, but I wasn't able to find the information that would help me produce a solution.
I basically have a Stackpanel, which has a Grid with defined Rows and Columns and I want to dynamically create a set amount of textboxes in differing Rows and Columns, that I can then use to interact with.
My solution up until now was to create every textbox one by one in WPF and then add all of them one by one to a List of Textboxes in C# to interact with them. But I really don't believe that this is a clean solution.
Example WPF
<TextBox x:Name="Std2018_01" Grid.Row="1" Grid.Column="1" Height="20" Width="50" TextAlignment="Center" BorderBrush="{x:Null}" TextChanged="Std2018_TextChanged"></TextBox>
<TextBox x:Name="Std2018_02" Grid.Row="2" Grid.Column="1" Height="20" Width="50" TextAlignment="Center" BorderBrush="{x:Null}" TextChanged="Std2018_TextChanged"></TextBox>
<TextBox x:Name="Std2018_03" Grid.Row="3" Grid.Column="1" Height="20" Width="50" TextAlignment="Center" BorderBrush="{x:Null}" TextChanged="Std2018_TextChanged"></TextBox>
C# Adding them to a List
boxes2018.Add(Std2018_01);
boxes2018.Add(Std2018_02);
boxes2018.Add(Std2018_03);
There has to be a better way to solve this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论