2012-08-14 144 views
0

嗨,我想用一個MouseDoubleClick事件給我的DataGridTemplateColumn,對於H.Column下的功能 - 和Processinterface-行。如何將MouseDoubleClick-事件綁定到DataGridTemplateColumn

但沒有MouseDoubleClick-事件DataGridTemplateColumn。 任何人都可以幫忙!

這是我的代碼:

<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> 

回答

0

然後添加代碼隱藏文件

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

+0

感謝名單了很多!!!!! – User1979 2012-08-14 13:18:42

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。另外,展示如何在模板上使用觸發器。

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" 
      /> 
相關問題