最佳答案
我在一个堆栈面板里有两个栅格。 第一个网格名为 GridX。 最初,在网格内部有一个2D 文本框数组(RowDefs/ColumnDefs)。 XAML 中的 TextBox 定义为
<TextBox x:Name="A1" Grid.Row="4" Grid.Column="5" TextAlignment="Center" />
我想以编程方式在 GridX 的相同位置添加一个 文本块。
效果一定是这样的
<TextBlock Grid.Row="4" Grid.Column="5"
HorizontalAlignment="Left" VerticalAlignment="Top" Text="10" FontSize="8"/>
如何添加这个。 我试过这个:
TextBlock tblock = new TextBlock();
GridX.SetColumn(tblock, cIndex);
GridX.SetRow(tblock, rIndex);
但失败了。
我又试了一次:
int rIndex = Grid.GetRow(txtBox);
int cIndex = Grid.GetColumn(txtBox);
TextBlock tblock = new TextBlock();
tblock.VerticalAlignment = VerticalAlignment.Top;
tblock.HorizontalAlignment = HorizontalAlignment.Left;
tblock.FontSize = 8;
tblock.Text = rc[i, j - 1];
Grid.SetColumn(tblock, cIndex);
Grid.SetRow(tblock, rIndex);
txtBox.MaxLength = 1;
现在的问题是 TextBlock 不可见。 TextBox 隐藏了它。 谢谢你的帮助。