将CellEditTemplate放在双击单元格DataGridRow WPF上 [英] Focus CellEditTemplate on double click cell DataGridRow WPF
问题描述
我有一个数据网格,想一次在单元格中显示超链接和普通文本.我已经为数据网格中的单元格定义了celltemplate和celleditingtemplate.我将选择模式设置为全行.
I have a datagrid and want to show hyperlink and normal text in cell at a time .I have defined celltemplate and celleditingtemplate for cells in the datagrid. I have set the selection mode to be a full row.
当我单击超链接后,除非启用焦点更改,否则不启用单元格编辑.单击超链接后,我要编辑单元格.当我双击单元格时,应该对其进行编辑.
有什么建议 ?请在下面查看我的代码
When i click on hyperlink after that cell editing is not enable unless i change focus from it. I want to edit cell after click on hyperlink. When i double click on cell then it should be edit.
Any suggestions ? Please see my code below
xmlns : 我的 = " clr-namespace:Microsoft.Windows.Controls; assembly = WPFToolkit"
< my:DataGrid Name =" Grid" HeadersVisibility =列" SelectionUnit ="FullRow"
HorizontalAlignment =拉伸"; VerticalAlignment =拉伸"
ItemsSource ="{绑定说明,UpdateSourceTrigger = PropertyChanged}"背景=白色". AutoGenerateColumns ="False"
BorderBrush =#FFB1B1B1" VerticalScrollBarVisibility =自动";
HorizontalScrollBarVisibility ="Auto"
HorizontalGridLinesBrush ="LightGray" ScrollViewer.CanContentScroll =" False"
VerticalGridLinesBrush ="LightGray" CanUserDeleteRows =假". CanUserResizeRows ="True" CanUserAddRows ="False">
< my:DataGrid.Columns>
< my:DataGridTextColumn Binding =" {Binding Path = TimestampString}"标头=时间戳". IsReadOnly ="True"/>
< my:DataGridTemplateColumn Header ="Notes" Width ="*">
< my:DataGridTemplateColumn.CellTemplate>
< DataTemplate>
< StackPanel Width ="Auto"背景=白色". >
< TextBlock Name ="tb"; 样式="{DynamicResource TextBlockStyle}" TextWrapping ="Wrap" 帮手:NavigationService.Text =" {绑定
注释}" ContextMenu =" {StaticResource TextBoxContextMenu}"></TextBlock>
</StackPanel>
</DataTemplate>
</my:DataGridTemplateColumn.CellTemplate>
< my:DataGridTemplateColumn.CellEditingTemplate>
< DataTemplate>
< TextBox AllowDrop =" False" AcceptsReturn ="True" TextWrapping ="Wrap"名称=注" Text =" {装订说明}">
</TextBox>
< DataTemplate.Triggers>
< Trigger SourceName =注释";属性=可见"值="True">
< Setter TargetName ="注意"属性="FocusManager.FocusedElement".值=" {Binding ElementName = Note}"/>
</Trigger>
</DataTemplate.Triggers>
</DataTemplate>
</my:DataGridTemplateColumn.CellEditingTemplate>
</my:DataGridTemplateColumn>
</my:DataGrid.Columns>
</my:DataGrid>
<my:DataGrid Name="Grid" HeadersVisibility="Column" SelectionUnit="FullRow"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
ItemsSource="{Binding Notes,UpdateSourceTrigger=PropertyChanged}" Background="White" AutoGenerateColumns="False"
BorderBrush="#FFB1B1B1" VerticalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Auto"
HorizontalGridLinesBrush="LightGray" ScrollViewer.CanContentScroll="False"
VerticalGridLinesBrush="LightGray" CanUserDeleteRows="False" CanUserResizeRows="True" CanUserAddRows="False">
<my:DataGrid.Columns>
<my:DataGridTextColumn Binding="{Binding Path=TimestampString}" Header="Timestamp" IsReadOnly="True"/>
<my:DataGridTemplateColumn Header="Notes" Width="*">
<my:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel Width="Auto" Background="White" >
<TextBlock Name="tb" Style="{DynamicResource TextBlockStyle}" TextWrapping="Wrap" Helpers:NavigationService.Text="{Binding
Notes}" ContextMenu="{StaticResource TextBoxContextMenu}"></TextBlock>
</StackPanel>
</DataTemplate>
</my:DataGridTemplateColumn.CellTemplate>
<my:DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<TextBox AllowDrop="False" AcceptsReturn="True" TextWrapping="Wrap" Name="Note" Text="{Binding Notes}">
</TextBox>
<DataTemplate.Triggers>
<Trigger SourceName="Note" Property="IsVisible" Value="True">
<Setter TargetName="Note" Property="FocusManager.FocusedElement" Value="{Binding ElementName=Note}"/>
</Trigger>
</DataTemplate.Triggers>
</DataTemplate>
</my:DataGridTemplateColumn.CellEditingTemplate>
</my:DataGridTemplateColumn>
</my:DataGrid.Columns>
</my:DataGrid>
推荐答案
我发现您对这两项要求的解释以及该代码非常令人困惑.
I find your explanation of both requirements and that code very confusing.
如果您想要超链接,那么为什么没有超链接?
If you want a hyperlink then why is there no hyperlink?
为什么用户希望能够编辑超链接?
Why would a user expect to be able to edit a hyperlink?
只有一列-为什么将选择设置为行?
There's only one column - why are you setting selection to row?
每行中只有一个文本块,但是它在堆栈面板中.
You only have textblock in each row, but it's inside a stackpanel.
为什么?
为什么DataGrid的前缀是"my:"?
Why is DataGrid prefixed by "my:"?
这篇关于将CellEditTemplate放在双击单元格DataGridRow WPF上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!