我想允许重新调整 dataGrid 的第零列的大小,该列包含 SelectAll 按钮和行标题 -
问问题
507 次
2 回答
1
试试这个...
XAML:
<tk:DataGrid x:Name="MyDataGrid"
RowHeaderWidth="15"
ItemsSource="{StaticResource MyData}"
AutoGenerateColumns="False">
<tk:DataGrid.Columns>
<tk:DataGridTextColumn Binding="{Binding ID}">
<tk:DataGridTextColumn.HeaderTemplate>
<DataTemplate>
<DockPanel>
<GridSplitter
DockPanel.Dock="Left"
VerticalAlignment="Stretch"
HorizontalAlignment="Left" Width="2"
DragDelta="GridSplitter_DragDelta"/>
<TextBlock Text="ID" DockPanel.Dock="Right"/>
</DockPanel>
</DataTemplate>
</tk:DataGridTextColumn.HeaderTemplate>
</tk:DataGridTextColumn>
<tk:DataGridTextColumn Header="Name"
Binding="{Binding Name}">
</tk:DataGridTextColumn>
</tk:DataGrid.Columns>
</tk:DataGrid>
代码背后:
private void GridSplitter_DragDelta
(object sender,
System.Windows.Controls.Primitives.DragDeltaEventArgs e)
{
if (MyDataGrid.RowHeaderWidth + e.HorizontalChange >= 15)
{
MyDataGrid.RowHeaderWidth = MyDataGrid.RowHeaderWidth + e.HorizontalChange;
}
}
您可以覆盖RowHeaderTemplate
并执行停靠在右侧的精确网格拆分器。但对我来说,将它停靠在第一列标题的左侧效果最好!
于 2012-03-06T13:57:37.640 回答
0
<GridViewColumn Header="Name" Width="150">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Width="Auto" TextTrimming="CharacterEllipsis"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
试试这个
于 2012-03-06T12:43:22.657 回答