我有checkbox
定义如下:
<GridViewColumn>
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox x:Name="CampaignCb" Tag="{Binding Campaign}" IsChecked="{Binding RelativeSource={RelativeSource AncestorType={x:Type ListViewItem}}, Path=IsSelected}" Checked="CampaignCb_Checked" Unchecked="CampaignCb_Unchecked" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
如何以编程方式取消选中所选的checkbox
?我尝试使用CampaignCb.IsChecked = false
,但由于我的复选框绑定了一个来源,因此对我的情况不起作用。
修改 以下是我将数据填充到列表视图中的方法:
CampaignTabLv.Items.Add(new
{
Campaign = OutboundConfig.campName[i], Status = OutboundConfig.campStatus[i].ToString(),
Mode = OutboundConfig.campDialMode[i].ToString(), Description = OutboundConfig.campDesc[i],
CampaignID = OutboundConfig.campID[i], GroupID = OutboundConfig.campGroupID[i],
OptimizeGoal = OutboundConfig.campOptimizeGoal[i], OptimizationMethod = OutboundConfig.campOptimizationMethod[i].ToString()
});
这就是我在选中checkbox
时的选择价值:
private void CampaignCb_Checked(object sender, RoutedEventArgs e)
{
var selectedCampaign = (dynamic)CampaignTabLv.SelectedItems[0];
}