我在整个互联网上进行了搜索,但找不到将表格列拉伸(stretch)到内容宽度以及如何将表格集中在屏幕中间的简单解决方案。它总是左对齐。我试过 <TableColumn width="Auto">
.它没有耍花招。唯一有用的是 <TableColumn width="200">
.如何使列拉伸(stretch)到内容宽度,以及如何将表格放在屏幕中间?或者,我应该只求助于网格选项吗?
这是我的 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>
这是我得到的结果:
最佳答案
让表格居中对齐
<Table HorizontalAlignment="Centre" VerticalAlignment="Center">
& 使列宽尝试使用 * 而不是 Auto 或输入一些数字然后 * 如“2*”
关于wpf - 表格列宽和水平对齐方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16390241/