How to limit max width of column?
I have a DataGrid with some columns, and I want one of columns 开发者_运维知识库to occupy all possible width to fill DataGrid, but no more. So it will wrap its text, if width of DataGrid is not enough. I used a TextWrapping, but it only works when setting fixed width for column. Is there any way achieve my goal? (make working both text wrapping and auto-size width?)
Since you haven't posted any xaml its not clear what you have tried. The following works fine:-
<sdk:DataGridTemplateColumn Width="*" Header="Memo">
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock TextWrapping="Wrap" Text="{Binding Memo}" />
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
<sdk:DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<TextBox TextWrapping="Wrap" Text="{Binding Memo}" />
</DataTemplate>
</sdk:DataGridTemplateColumn.CellEditingTemplate>
</sdk:DataGridTemplateColumn>
I got some similar case on WPF, you should try it,
Create an attached behavior, that will set the Width of the column to be same as actual Width of the column, after the grid or the column is loaded.
This way you get the ability of auto Witdh calculation by SL and have a fixed Witdh so wrapping will work.
精彩评论