0

嗨,我想对我的 DataGridTemplateColumn 使用 MouseDoubleClick 事件,用于 H.Column 下的 Function-和 Processinterface-Row。

但 DataGridTemplateColumn 没有 MouseDoubleClick-Event。谁能帮忙!

这是我的代码:

   <DataGridTemplateColumn x:Name="" Header="H." Width="50">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <DataTemplate.Triggers>
                                    <DataTrigger Binding="{Binding Path=ObjectType}" Value="E">
                                        <Setter Property="Visibility" Value="Hidden" />
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding Path=ObjectType}" Value="Function">
                                        <Setter Property="Visibility" Value="Visible" />
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding Path=ObjectType}" Value= "Processinterface">
                                        <Setter Property="Visibility" Value="Visible" />
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding Path=ObjectType}" Value="AND">
                                        <Setter Property="Visibility" Value="Hidden" />
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding Path=ObjectType}" Value="OR">
                                        <Setter Property="Visibility" Value="Hidden" />
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding Path=ObjectType}" Value="XOR">
                                        <Setter Property="Visibility" Value="Hidden" />
                                    </DataTrigger>
                                </DataTemplate.Triggers>
                                <Button Name="btnTable" Visibility="Hidden" Height="20" Width="25" Click="Button_Table_Click">
                                    <Image Height="16" Source="" Stretch="Fill" Width="16"/>
                                </Button>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
4

3 回答 3

0

像这样写

<my:DataGrid 
            AutoGenerateColumns="False" 
            Margin="22,263,0,0" 
            Name="dgAcctSearch"  
            xmlns:my="http://schemas.microsoft.com/wpf/2008/toolkit" 
            IsReadOnly="True" 
            CanUserResizeRows="False" 
            CanUserSortColumns="True" 
            SelectionMode="Extended" 
            SelectionUnit="Cell" 
            HorizontalAlignment="Left" 
            Width="783" 
            Height="331" 
            VerticalAlignment="Top" 
            MouseDoubleClick="dgAcctSearch_MouseDoubleClick" 
            CanUserAddRows="False" 
            CanUserDeleteRows="False"  
            CanUserReorderColumns="False" 
            CanUserResizeColumns="True" 
            AllowDrop="False"
            Background="WhiteSmoke"
            GridLinesVisibility="All"
            />
于 2012-08-14T11:27:06.243 回答
0

then add in code behind file

private void dgAcctSearch_MouseDoubleClick(object sender, MouseButtonEventArgs e) { //add your logic here }

于 2012-08-14T11:31:15.773 回答
0
<DataGrid MouseDoubleClick="dataGridLog_MouseDoubleClick" ItemsSource="{Binding}" RowDetailsVisibilityMode="VisibleWhenSelected">
        <DataGrid.Columns>
            <DataGridTemplateColumn x:Name="dateColumn" Header="Date" Width="80" CanUserReorder="True" CanUserSort="False">
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock x:Name="dateColumnTextBlock" Text="{Binding Path=DateSent, StringFormat={}{0:dd/MM/yyyy}}" Width="80" />
                        <DataTemplate.Triggers>
                            <DataTrigger Binding="{Binding Path=DateSent, StringFormat={}{0:dd/MM/yyyy}, Converter={x:Reference Name=DateConverter}, ConverterParameter=>3}" Value="True">
                                <Setter TargetName="dateColumnTextBlock" Property="Background" Value="Red" />
                            </DataTrigger>
                        </DataTemplate.Triggers>
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
            </DataGridTemplateColumn>

            <DataGridTemplateColumn x:Name="priorityColumn" Header="Priority" Width="80" CanUserReorder="True" CanUserSort="True">
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock x:Name="priorityColumnTextBlock" Text="{Binding Path=Priority}" Width="80" />
                        <DataTemplate.Triggers>
                            <DataTrigger Binding="{Binding Path=Priority}" Value="Urgent">
                                <Setter TargetName="priorityColumnTextBlock" Property="FontWeight" Value="Bold" />
                            </DataTrigger>
                        </DataTemplate.Triggers>
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
            </DataGridTemplateColumn>

            <DataGridTextColumn x:Name="titleColumn" Binding="{Binding Path=Fault}" Header="Title" Width="270" CanUserReorder="True" CanUserSort="True" />
        </DataGrid.Columns>
    </DataGrid>

这本质上是我的 daragrid。我已经展示了这个以证明它确实具有MouseDoubleClick. 此外,还展示了如何在模板上使用触发器。

于 2012-08-14T10:59:56.903 回答