tags:

views:

255

answers:

1

Hi,

The following code is part of a small XAML application that displays data in a tabular form. Basically I need to translate this code into 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>

I've been looking for an answer for a couple of days and I can't find anything specific to this. Can someone please give me an idea of how to do it?

Thank you

A: 

I constructed a sample Window for you. Here is the code-behind you are looking for:

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;
}

This example nicely demonstrates how easy XAML is for constructing user interfaces. :)

Charlie
Thank you, Charlie. It's an excelent example you posted. And it works indeed in a WPF application for Windows and WPF browser application as well. As soon as I try it in an ASP.NET application, nothing shows up. This ASP.NET application builds an XPS document (FixedDocument) on the server and then sends it as a stream to the client for viewing. Is there something I'm not aware of related to XPS (FixedDocument) or ASP.NET? I really appreciate your help.
Cezar
I am not entirely sure about ASP.NET, as that is not my area of expertise. You could try asking about that in a separate question. Also, you should accept my answer if it helped you out! :)
Charlie
The code works fine in ASP.NET as well. There was a bug in my code that was stopping the application display the text. Thank you again.
Cezar