双击获取当前行的控件

By admin in 4858.com on 2019年4月3日
<DataGrid Margin="10" HorizontalAlignment="Left" VerticalAlignment="Top" AutoGenerateColumns="False" ItemsSource="{Binding }" Name="dg_cards"  MouseDoubleClick="dg_cards_MouseDoubleClick" >
<DataGrid.Columns>
<DataGridTextColumn Header="ID" Width="40" Binding="{Binding index}" IsReadOnly="True" />
<DataGridTemplateColumn Header="启用" Width="50">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox Name="cbStatus" MinWidth="{Binding ID}" Uid="{Binding Path=ID}" IsChecked="{Binding IsChecked}" Tag="{Binding ID}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="卡口" Width="80" IsReadOnly="True" Binding="{Binding cardname}" />
<DataGridTemplateColumn Header="八端口卡" Width="80">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox Name="cbeight" IsChecked="{Binding IsEChecked}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

<DataGridTextColumn Header="操作" Width="80" IsReadOnly="True" Binding="{Binding op}" />
</DataGrid.Columns>
</DataGrid>

4858.com ,双击获取当前行的控件。 

后台代码:

 private void dg_cards_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            bool isEight = false;
            DataGrid dg = sender as DataGrid;

            //双击获取第三列的控件
            DataGridTemplateColumn templeColumn1 = dg.Columns[3] as DataGridTemplateColumn;
            FrameworkElement fwElement1 = dg_cards.Columns[3].GetCellContent(dg.CurrentItem);
            CheckBox cBox1 = templeColumn1.CellTemplate.FindName("cbeight", fwElement1) as CheckBox;
            if ((bool)cBox1.IsChecked) {
                isEight = true;
            }
        }

  

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图
Copyright @ 2010-2019 美高梅手机版4858 版权所有