<DataGridTemplateColumn Width="3*" Header="Description"
HeaderStyle="{StaticResource gridHeaderStyle}"
ScrollViewer.IsDeferredScrollingEnabled="True">
<DataGridTemplateColumn.CellTemplate >
<DataTemplate >
<ScrollViewer VerticalScrollBarVisibility="Auto" Width="Auto"
CanContentScroll="True" Height="Auto" MaxHeight="100">
<TextBlock Text="{Binding Description}"
Width="Auto" Height="Auto" TextWrapping="Wrap"
xml:space="preserve" />
</ScrollViewer>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<ScrollViewer VerticalScrollBarVisibility="Auto"
Width="Auto" CanContentScroll="True" Height="Auto"
MaxHeight="100">
<TextBox AcceptsReturn="True" Width="Auto" Height="Auto"
Text="{Binding Description, NotifyOnTargetUpdated=True,
Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
TextWrapping="Wrap" xml:space="preserve" />
</ScrollViewer>
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
我在细胞模板和细胞编辑模板周围使用滚动条
双击单元格时,它不会进入编辑模式
如果我从单元格模板中删除滚动条,则允许双击编辑
但我想在细胞模板和编辑模板
周围显示滚动条如果按F2键进入编辑模式但鼠标双击不起作用
任何解决方案??
答案 0 :(得分:0)
<DataGridTemplateColumn Width="3*" Header="Description" HeaderStyle=" {StaticResource gridHeaderStyle}" ScrollViewer.IsDeferredScrollingEnabled="True">
<DataGridTemplateColumn.CellTemplate >
<DataTemplate >
<ScrollViewer VerticalScrollBarVisibility="Auto" Width="Auto" CanContentScroll="True" Height="Auto" MaxHeight="100"
MouseDoubleClick="ScrollViewer_MouseDoubleClick">
<TextBlock Text="{Binding Description}" Width="Auto" Height="Auto" TextWrapping="Wrap" xml:space="preserve" />
</ScrollViewer>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<ScrollViewer VerticalScrollBarVisibility="Auto" Width="Auto" CanContentScroll="True" Height="Auto" MaxHeight="100">
<TextBox AcceptsReturn="True" Width="Auto" Height="Auto" Text="{Binding Description, NotifyOnTargetUpdated=True,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" TextWrapping="Wrap" xml:space="preserve" /></ScrollViewer>
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
需要在滚动查看器上添加事件
private void ScrollViewer_MouseDoubleClick(object sender,MouseButtonEventArgs e)
{
grid.BeginEdit();
}
从msdn论坛得到答案