【问题标题】:MouseDoubleClick Event on DatagridTemplateColumnDatagridTemplateColumn 上的 MouseDoubleClick 事件
【发布时间】:2011-08-15 08:07:08
【问题描述】:

如何在 DatagridTemplateColumn 上添加 MouseDoubleClick 事件?

我的专栏:

<DataGridTemplateColumn Header="PK"> 
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <Image Name="pk" HorizontalAlignment="Center" Stretch="None" />
            <DataTemplate.Triggers>
                <DataTrigger Binding="{Binding Path=Primary_Key}" Value="J">
    <Setter TargetName="pk" Property="Source" Value="/UserInterface;component/Resources/Images/key.png"/>
                </DataTrigger>
            </DataTemplate.Triggers>
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

我现在在 DataGrid 本身上使用 MouseDoubleClick 事件来执行此操作,但是每次双击任何单元格时都会触发此offcourse:

Private Sub dgColumns_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Input.MouseButtonEventArgs)
    Dim dg As DataGrid = CType(sender, DataGrid)
    If dg.SelectedItem IsNot Nothing AndAlso dg.SelectedItem.GetType Is GetType(Attribuut) Then
        If CType(dg.SelectedItem, Attribuut).Primary_Key = "J" Then
            CType(dg.SelectedItem, Attribuut).Primary_Key = "N"
        Else
            CType(dg.SelectedItem, Attribuut).Primary_Key = "J"
        End If
    End If
End Sub

这会使图像列发生变化,但只有当我离开单元格时,我将如何立即执行此操作?

【问题讨论】:

    标签: wpf vb.net xaml double-click datagridtemplatecolumn


    【解决方案1】:

    我建议将您的图像包装在 ContentControl 中。 ContentControl 是 Control 的子类。 MouseDoubleClick 在 Control 类中定义。

    <ContentControl MouseDoubleClick="cc_MouseDoubleClick">
        <Image Name="pk" Source="my.png" HorizontalAlignment="Center" Stretch="None" />
    </ContentControl>
    

    【讨论】:

    • 直到图像设置为Nothing,然后没有任何东西可以点击。我将如何克服这个问题?
    • 通过在图像周围的 contentControl 中添加具有透明背景的边框来解决此问题。但我仍然需要分散注意力才能看到​​数据网格中的图像发生变化。
    • 可以用别的东西包裹起来吗?
    • 这很奇怪。我不需要散焦就可以看到图像。您是否将 INotifyPropertyChanged 用于您的 Attribuut 类?
    猜你喜欢
    • 1970-01-01
    • 2011-02-19
    • 2014-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-31
    相关资源
    最近更新 更多