wpf datagrid 的单元格内容超出列宽度

 1 <Window x:Class="WpfApplication2.MainWindow"
 2     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 3     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 4     Title="MainWindow" Height="350" Width="525">
 5 <Grid>
 6     <DataGrid Name="grid1" AutoGenerateColumns="False">
 7         <DataGrid.Columns>
 8             <!--自定义列-->
 9             <DataGridTemplateColumn Header="姓名" Width="30" MaxWidth="100">
10                 <DataGridTemplateColumn.CellTemplate>
11                     <DataTemplate>
12                         <!--设置当单元格内容超过最大长度时,显示...-->
13                         <TextBlock Text="{Binding Name}" TextTrimming="WordEllipsis"/>
14                     </DataTemplate>
15                 </DataGridTemplateColumn.CellTemplate>
16                 <DataGridTemplateColumn.CellStyle>
17                     <Style>
18                          <!--加tooltip,显示单元格内容-->
19                         <Setter Property="ToolTipService.ToolTip" Value="{Binding Name}"/>
20                     </Style>
21                 </DataGridTemplateColumn.CellStyle>
22             </DataGridTemplateColumn>
23             <DataGridTextColumn Header="年龄" Binding="{Binding Age}" Width="50"/>
24         </DataGrid.Columns>
25     </DataGrid>
26 </Grid>

 

posted @ 2018-04-26 19:36  softwyy  阅读(1866)  评论(0编辑  收藏  举报