Greetings

There is a fairly large table, the contents of the columns of which are very heterogeneous. For example, 10 rows in a column have a length of ~ 10-12 characters and the last 20-30. Because of this, it is not convenient to use a fixed width of the columns - line 11 does not fit. But setting the width of the content is also not always appropriate. because of one long line the whole column will expand. On low resolution monitors it is still worse. Actually, the question is how to implement such that the columns would display, for example, the first 12 characters, and when you hover, is the entire contents of the cell?

Datagrid itself:

<DataGrid Style="{StaticResource StyleTable}" x:Name="DGInvestmentDetails" Grid.Row="1" Grid.RowSpan="3" ItemsSource="{Binding InvestCollection}" AutoGenerateColumns="False" RowHeight="24" IsReadOnly="True" CurrentCell="{Binding CellInfo, Mode=OneWayToSource}" Margin="0,0,0,71"> <DataGrid.Columns> <DataGridTextColumn Header="Type" Width="auto" Binding="{Binding Type}"/> <DataGridTextColumn Header="Currency" MinWidth="50" Width="auto" Binding="{Binding Value}"/> <DataGridTextColumn Header="Date" Width="auto" Binding="{Binding Date}"/> <DataGridTextColumn Header="Units" MinWidth="90" Width="auto" Binding="{Binding Units}"/> <DataGridTextColumn Header="Aq.Price" MinWidth="80" Width="auto" Binding="{Binding AqPr}"/> <DataGridTextColumn Header="Quote" MinWidth="80" Width="auto" Binding="{Binding Quote}"/> <DataGridTextColumn Header="Isin" Width="auto" Binding="{Binding Isin}"/> <DataGridTextColumn Header="Market Value" MinWidth="100" Width="auto" Binding="{Binding Markedvalue}" /> <DataGridTextColumn Header="Market Value USD" Width="auto" Binding="{Binding MarkedvalueUSD}"/> <DataGridTextColumn Header="Profit USD" MinWidth="100" Width="auto" Binding="{Binding profit}"/> <DataGridTextColumn Header="Percent" MinWidth="80" Width="auto" Binding="{Binding Percent}" /> <DataGridTextColumn Header="Valuation Date" MinWidth="100" Width="auto" Binding="{Binding currentDate}"/> </DataGrid.Columns> </DataGrid> 
  • one
    mmm, and tried to install ToolTip ? - Andrey NOP
  • Somewhere, by the way, here on ruSO saw the implementation of the converter (sort of from @VladD, if it comes to the topic - it can find it), which cut the line and added to it ... if it does not fit into the allotted space. Set this trimmed value as Text for TextBlock, and the full value as ToolTip - Andrey NOP
  • @Andrew ToolTip did not install and did not use. Does it replace the DataGrid ? - Sergey
  • Why replace? Override the CellTemplate (or whatever it’s called in the grid) and install the TextBlock instead, which you install ToolTip - Andrey NOP
  • one

1 answer 1

An example of markup using ToolTip :

 <DataGrid ItemsSource="{Binding Users}" AutoGenerateColumns="False"> <DataGrid.Columns> <DataGridTemplateColumn Header="Имя" Width="100"> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <TextBlock Text="{Binding Name}" ToolTip="{Binding Name}"/> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn> <DataGridTextColumn Header="Возраст" Binding="{Binding Age}"/> <DataGridTemplateColumn Header="Адрес" Width="100"> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <TextBlock Text="{Binding Address}" ToolTip="{Binding Address}"/> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn> </DataGrid.Columns> </DataGrid> 

enter image description here

  • Thank! Exactly what the doctor ordered! - Sergey
  • Do not tell me, what is the name of the tool - when, when you click on a row in a DataGrid, the table unfolds to a new row with content? I can not remember the name. - Sergey
  • @ Sergey: row details ? - Andrey NOP
  • Yes exactly! Plus you would be 2 times if you could. Thanks again. - Sergey