以下代码是以表格形式显示数据的小型XAML应用程序的一部分。基本上我需要将此代码翻译成C#。
<Grid Width="768" Height="1056">
<Grid.RowDefinitions>
<RowDefinition Height="114" />
<RowDefinition Height="906*" />
<RowDefinition Height="36" />
</Grid.RowDefinitions>
...
<Label Grid.Row="1" Width="40" Height="32" Margin="14,4,0,0" Padding="0" HorizontalAlignment="Left" VerticalAlignment="Top" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" BorderBrush="Black" BorderThickness="1" Name="label16">
<AccessText Margin="0,0,0,0" TextWrapping="Wrap" TextAlignment="Center" FontWeight="Bold">
SEQ
</AccessText>
</Label>
...
</Grid>
我一直在寻找答案,我找不到任何具体的内容。有人可以告诉我如何做到这一点吗?
谢谢
答案 0 :(得分:2)
我为你构建了一个样本Window
。以下是您正在寻找的代码隐藏:
public Window1()
{
InitializeComponent();
AccessText text = new AccessText()
{
Text = "SEQ",
Margin = new Thickness(0),
TextWrapping = TextWrapping.Wrap,
TextAlignment = TextAlignment.Center,
FontWeight = FontWeights.Bold
};
Label label = new Label()
{
Content = text,
Width = 40,
Height = 32,
Margin = new Thickness(14, 4, 0, 0),
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Top,
HorizontalContentAlignment = HorizontalAlignment.Center,
VerticalContentAlignment = VerticalAlignment.Center,
BorderBrush = Brushes.Black,
BorderThickness = new Thickness(1),
Name = "label16"
};
Grid grid = new Grid();
grid.Width = 768;
grid.Height = 1056;
grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(114) });
grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(906, GridUnitType.Star) });
grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(36) });
Grid.SetRow(label, 1);
grid.Children.Add(label);
this.Content = grid;
}
此示例很好地演示了XAML构建用户界面的简便性。 :)