我有一個帶有文本列,兩個模板列和兩個複選框列的WPF數據格式。
模板列垂直居中對齊(相同的填充頂部和底部),文本列頂部有一點填充,但底部有很多填充,複選框頂部只有大約1個像素填充。在Datagrid行上填充
我想垂直居中對齊它們,但我不想讓模板列包含複選框和文本框。
這樣做的正確方法是什麼?
編輯:XAML
<DataGrid AutoGenerateColumns="False" Name="dgROList" ItemsSource="{Binding ElementName=MainWindow, Path=cROInfo}" CanUserDeleteRows="True" CanUserReorderColumns="False" GridLinesVisibility="Horizontal" Margin="0,0,0,0" Grid.ColumnSpan="2" AlternatingRowBackground="#FFFFE776">
<DataGrid.ContextMenu>
<ContextMenu>
<MenuItem Name="mnuDelete" Header="Delete" />
</ContextMenu>
</DataGrid.ContextMenu>
<DataGrid.Columns>
<DataGridTextColumn Header="RO Number" Width="Auto" Binding="{Binding RONum}" />
<DataGridTemplateColumn x:Name="roDetails" Header="RO Details" Width="*">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ItemsControl Name="LineDetails" ItemsSource="{Binding LineInfo}" Width="Auto" Grid.IsSharedSizeScope="True">
<ItemsControl.Template>
<ControlTemplate TargetType="ItemsControl">
<ItemsPresenter />
</ControlTemplate>
</ItemsControl.Template>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20" />
<ColumnDefinition Width="Auto" SharedSizeGroup="DetailCol"/>
<ColumnDefinition Width="50" />
<ColumnDefinition Width="150*"/>
</Grid.ColumnDefinitions>
<Label Content="{Binding Line}" Grid.Column="0" />
<Label Content="{Binding Status}" Grid.Column="1" />
<Label Content="{Binding AmountPaid}" Grid.Column="2" />
<Label Content="{Binding SDate}" Grid.Column="3" />
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn x:Name="roRI" Header="RI" Width="Auto" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Label Content="{Binding RI}" ToolTipService.ShowDuration="60000" ></Label>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridCheckBoxColumn Header="Paid" Width="40" Binding="{Binding Paid}" />
<DataGridCheckBoxColumn Header="Adj" Width="30" Binding="{Binding Adjustment}" />
</DataGrid.Columns>
</DataGrid>
編輯2:其實,我也不需要垂直對齊。只需在頂部添加一點填充,以便與模板列的頂部對齊。
你能告訴XAML? – sll
OK,這裏是XAML – AndyD273
有幾個建議位置: http://stackoverflow.com/questions/3981250/datagrid-row-content-vertical-alignment – Scott