我在互联网上搜索并找不到将表格列拉伸到内容宽度的简单解决方案,以及如何将表格集中在屏幕中间。它始终与左侧对齐。我试过了<TableColumn width="Auto">
。它没有成功。唯一有效的是<TableColumn width="200">
。如何使列拉伸到内容宽度,如何将表放在屏幕中间?或者,我应该采用网格选项吗?
这是我的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>
这就是我得到的结果:
答案 0 :(得分:-2)
使表格中心对齐
<Table HorizontalAlignment="Centre" VerticalAlignment="Center">
&安培;使列宽尝试使用*而不是自动或放一些数字然后*像“2 *”