我有一个数据网格,可以从项目源动态获取数据。
项目来源的一个字段是bool(复选框列),我想知道用户何时点击复选框。
是哪个活动?
xaml代码:
public class TableList
{
private string _field;
public string Field
{
get { return _field; }
set { _field = value; }
}
private string _val;
public string Val
{
get { return _val; }
set { _val = value; }
}
private bool _calc;
public bool Calc
{
get { return _calc; }
set { _calc = value; }
}
}
/// <summary>
/// Interaction logic for createByProtocol.xaml
/// </summary>
public partial class createByProtocol : Window
{
private ProtocolData.ProtocolData.Protocols _runningProtocol;
private List<TableList> _Ltbl;
public createByProtocol(ProtocolData.ProtocolData.Protocols protocol)
{
InitializeComponent();
_runningProtocol = protocol;
_Ltbl = new List<TableList>();
buildTable();
}
private void buildTable()
{
switch (_runningProtocol)
{
case ProtocolData.ProtocolData.Protocols.ZBM:
TableList tl = new TableList();
tl.Field = "Length";
tl.Val = "";
tl.Calc = false;
_Ltbl.Add(tl);
tl = new TableList();
tl.Field = "OpCode";
tl.Val = "";
_Ltbl.Add(tl);
tl = new TableList();
tl.Field = "REQ_ID";
tl.Val = "";
_Ltbl.Add(tl);
tl = new TableList();
tl.Field = "Message Type";
tl.Val = "";
_Ltbl.Add(tl);
tl = new TableList();
tl.Field = "DATA";
tl.Val = "";
_Ltbl.Add(tl);
tl = new TableList();
tl.Field = "CS";
tl.Val = "";
_Ltbl.Add(tl);
tl = new TableList();
tl.Field = "EOM";
tl.Val = "0A";
_Ltbl.Add(tl);
break;
}
dataGridTable.ItemsSource = _Ltbl;
}
}
C#:
$( "#mdp" ).focusin(function(){});
答案 0 :(得分:0)
看起来您正在使用自动生成的列或DataGridCheckBoxColumn,因此想知道如何选中/取消选中CheckBox。你必须在DataGrid级别处理CheckBox.Click,CheckBox.Checked,CheckBox.Unchecked附加事件。
<DataGrid x:Name="DgrdRight" CheckBox.Click="DgrdRight_Click" CheckBox.Checked="DgrdRight_Checked" CheckBox.Unchecked="DgrdRight_Unchecked" Grid.Column="1" Grid.Row="0" Margin="10,0,0,0" ColumnWidth="SizeToHeader" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Header="Title" Binding="{Binding Title}"/>
<DataGridCheckBoxColumn ... />
</DataGrid.Columns>
</DataGrid>
代码中的处理程序:
private void DgrdRight_Checked(object sender, RoutedEventArgs e)
{
System.Diagnostics.Debug.WriteLine("Checked");
}
private void DgrdRight_Unchecked(object sender, RoutedEventArgs e)
{
System.Diagnostics.Debug.WriteLine("UnChecked");
}
private void DgrdRight_Click(object sender, RoutedEventArgs e)
{
System.Diagnostics.Debug.WriteLine("Clicked");
}