答案 0 :(得分: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
并将此精确的网格分割器停靠在右侧。但对我来说,将它停靠在第一列标题左侧效果最好!
答案 1 :(得分:0)
<GridViewColumn Header="Name" Width="150">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Width="Auto" TextTrimming="CharacterEllipsis"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
试试这个