3

我在整个互联网上搜索,找不到将表格列拉伸到内容宽度的简单解决方案,以及如何将表格集中在屏幕中间。它始终与左侧对齐。我试过了<TableColumn width="Auto">。它没有起到任何作用。唯一有效的是<TableColumn width="200">。如何使列拉伸到内容宽度,如何将表格放在屏幕中间?或者,我应该只使用 Grid 选项吗?

这是我的 XAML:

<src:BaseSurveyElement x:Class="Question14"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:src="clr-namespace:DAQExperiment"
Title="Question14" FontStyle="Normal" FontSize="20" WindowState="Maximized" >

<Grid Height="600" Width="1100">


    <Grid.RowDefinitions>
        <RowDefinition Height="2*"/>
        <RowDefinition Height="2*"/>
    </Grid.RowDefinitions>

    <!-- <FlowDocumentReader Grid.Row="0" Name="FlowDocReader" Margin="2 2 2 2" ViewingMode="Scroll"/> -->
    <TextBlock Name="txtBlock" Grid.Row="0" Margin="20" TextWrapping="Wrap" />
    <!--<ScrollViewer Height="500" Width="1100"  Grid.Row="1"
        VerticalScrollBarVisibility="Visible" CanContentScroll="True">-->

        <FlowDocumentReader Grid.Row="1" UseLayoutRounding="True" SnapsToDevicePixels="True" Width="1200">
            <FlowDocumentReader.Resources>
                <Style TargetType="TableCell">
                    <Setter Property="TextAlignment" Value="Center"/>
                </Style>
            </FlowDocumentReader.Resources>
            <FlowDocument  >

                <Table CellSpacing="0" TextAlignment="Justify"  >
                    <Table.Columns >
                        <TableColumn />
                        <TableColumn />
                        <TableColumn />
                        <TableColumn />
                        <TableColumn />
                        <TableColumn />
                        </Table.Columns>
                <TableRowGroup Paragraph.TextAlignment="Center" >
                        <TableRow>
                            <TableCell BorderBrush="Black" BorderThickness="1">
                                <Paragraph FontWeight="Bold"></Paragraph>
                            </TableCell>
                            <TableCell BorderBrush="Black" ColumnSpan="2" BorderThickness="0,1,1,1">
                                <Paragraph FontWeight="Bold">Option A</Paragraph>
                            </TableCell>
                            <TableCell BorderBrush="Black" ColumnSpan="2" BorderThickness="0,1,1,1">
                                <Paragraph FontWeight="Bold">Option B</Paragraph>
                            </TableCell>
                            <TableCell BorderBrush="Black" BorderThickness="0,1,1,1">

                            </TableCell>
                        </TableRow>
                        <TableRow>
                            <TableCell BorderBrush="Black" BorderThickness="1,0,1,1">
                                <Paragraph FontWeight="Bold">Subscription</Paragraph>
                            </TableCell>
                            <TableCell BorderBrush="Black" BorderThickness="0,0,1,1">
                                <Paragraph>Monthly</Paragraph>
                            </TableCell>
                            <TableCell BorderBrush="Black" BorderThickness="0,0,1,1">
                                <Paragraph>Yearly</Paragraph>
                            </TableCell>
                            <TableCell BorderBrush="Black" BorderThickness="0,0,1,1">
                                <Paragraph>Monthly</Paragraph>
                            </TableCell>
                            <TableCell BorderBrush="Black" BorderThickness="0,0,1,1">
                            <Paragraph>Monthly</Paragraph>
                         </TableCell>
                         <TableCell BorderBrush="Black" BorderThickness="0,0,1,1">
                            <Paragraph>
                                <StackPanel Orientation="Vertical"  Margin="10,5,10,10" Name="spl1RdBtn">
                                    <RadioButton  GroupName="rbtngrp1" Content="Choice A" Margin="0,0,20,0" Name="rbtn1A" />
                                    <RadioButton GroupName="rbtngrp1" Content="Choice B" Margin="0,0,20,0" Name="rbtn1B" />
                                </StackPanel>
                            </Paragraph>
                        </TableCell>
                    </TableRow>
                        <TableRow>
                            <TableCell BorderBrush="Black" BorderThickness="1,0,1,1" TextAlignment="Center">
                                <Paragraph FontWeight="Bold">Price</Paragraph>
                            </TableCell>
                            <TableCell BorderBrush="Black" BorderThickness="0,0,1,1">
                                <Paragraph>$120.00</Paragraph>
                            </TableCell>
                            <TableCell BorderBrush="Black" BorderThickness="0,0,1,1">
                                <Paragraph>$1000.00</Paragraph>
                            </TableCell>
                            <TableCell BorderBrush="Black" BorderThickness="0,0,1,1">
                                <Paragraph>$130.00</Paragraph>
                            </TableCell>
                        </TableRow>
                    </TableRowGroup>
                </Table>
            </FlowDocument>
        </FlowDocumentReader>
    <!--</ScrollViewer>-->

</Grid>

<Window.Background>
    <LinearGradientBrush EndPoint="0.5,0" StartPoint="0.5,1">
        <GradientStop Color="Gray" Offset="0" />
        <GradientStop Color="White" Offset="1" />
    </LinearGradientBrush>
</Window.Background>

这是我得到的结果: 在此处输入图像描述

4

1 回答 1

-2

使表格居中对齐

<Table HorizontalAlignment="Centre" VerticalAlignment="Center">

& 使列宽尝试使用 * 而不是 Auto 或输入一些数字,然后 * 像 "2*"

于 2014-06-25T10:18:47.523 回答