由于奇怪的要求,我需要禁用用户通过单击事件更改复选框的 IsChecked 属性的能力。我无法禁用该复选框,因为右键单击它会显示一个上下文菜单,该菜单为控件提供了一些选项,包括允许用户通过某些属性控制复选框的 IsChecked 状态。有没有办法在不创建从该控件扩展的类的情况下执行此操作?这是在 c# 中使用 wpf 复选框。
如果项目的复选框被选中,我正在尝试使用预填充列表的复选框来执行操作。
在我的模型中,我有一个列表,它使用 GET 函数填充除 AddThis 布尔值之外的每个属性:
Public Property TaskList As List(Of TaskItem)
Get
Return (From a In db.Web.Backlogs
Join b In db.Web.References On a.StatusID Equals b.RefID
Where a.RelateSprint Is Nothing And b.Name <> "Resolved" And b.Name <> "Closed"
Select New TaskItem With {
.ItemID = a.ItemID,
.ItemName = a.ItemName,
.RelateItem = If(a.RelateItem IsNot Nothing, a.RelateItem, 0),
.OwnerID = If(a.UserIDOwn IsNot Nothing, a.UserIDOwn, 0),
.TypeID = If(a.TypeID IsNot Nothing, a.TypeID, 0),
.Type = If(db.Web.Backlogs.Count(Function(t) t.RelateItem = a.ItemID) > 0, "Epic", If(a.TypeID …Run Code Online (Sandbox Code Playgroud) 我有一个复选框列表,如下所示:
<div class="checkbox-list">
<label><input type="checkbox" value="" /> All items</label><br />
<label><input type="checkbox" value="1" /> First item</label><br />
<label><input type="checkbox" value="2" /> Second item</label><br />
<label><input type="checkbox" value="3" /> Third item</label><br />
<label><input type="checkbox" value="4" /> Forth Checkbox</label>
</div>
Run Code Online (Sandbox Code Playgroud)
我正在寻找的行为是,如果我在选中此div( .checkbox-list input[type=checkbox]:first) 所有其他复选框后选中第一个复选框。同样,如果我选择第一个以外的任何一个,第一个将被取消选择。
我正在努力如何检查第一个是否被点击?
$(".checkbox-list").on("change", "input[type=checkbox]", function () {
if ($(this).first()) { // <- not working - how do I know if I clicked the first one?
$("input[type=checkbox]:checked", ".checkbox-list").not(this).prop("checked", false);
$(this).prop("checked", true);
} else {
// Uncheck first …Run Code Online (Sandbox Code Playgroud) 我在使用 jQuery 使复选框表现得像收音机时遇到了困难,所以我只能选中三个复选框中的一个
<legend>Choose your delivery option!</legend>
<label>
<input type="checkbox" id="delivery" name="delivery" value="standard" />
Standard Delivery
</label>
<label>
<input type="checkbox" id="delivery" name="delivery" value="2day" />
2 Day Shipping
</label>
<label>
<input type="checkbox" id="delivery" name="delivery" value="overnite" />
Overnight Shipping
</label>
Run Code Online (Sandbox Code Playgroud) 我想在单击按钮时切换复选框。
这是我的 jQuery
$("#choose_address2").on("click", function () {
console.log("click!!! address2");
var $checkbox = $(this).find(':checkbox');
var checkBoxes = $("input[name=checkbox]]");
checkBoxes.prop("checked", !checkBoxes.prop("checked"));
});
Run Code Online (Sandbox Code Playgroud)
这是我的输入
<span id="choose_address2" class="btn btn-info">
<i class="fa fa-plus-circle"></i>????????????
<input type="checkbox" name="choose_address" {{#if customer.addresses}}checked{{/if}} id="choose_address1" hidden>
</input></span>
Run Code Online (Sandbox Code Playgroud)
默认情况下,该按钮处于选中状态。但是,当我单击带有 id 的跨度时,choose_address2我想更改状态。任何建议将不胜感激。
我想要一个类似于复选框的单选按钮,所以我在字典文件中定义了一个样式,如:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfCheckBoxLikeRadiobutton">
<Style x:Key="MyRadioButton" TargetType="{x:Type RadioButton}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type RadioButton}">
<Grid>
<CheckBox
IsChecked="{Binding RelativeSource={RelativeSource TemplatedParent},
Path=IsChecked, Mode=TwoWay}"
IsHitTestVisible="False" />
<CheckBox
IsChecked="{Binding RelativeSource={RelativeSource TemplatedParent},
Path=IsChecked, Mode=TwoWay}" Opacity="0"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Run Code Online (Sandbox Code Playgroud)
并像这样将其合并到 app.xaml 文件中
<Application x:Class="WpfCheckBoxLikeRadiobutton.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfCheckBoxLikeRadiobutton"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Dictionary1.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Run Code Online (Sandbox Code Playgroud)
然后在我的窗口中使用它
<GroupBox Margin="5" Padding="5">
<StackPanel >
<CheckBox Content="this is checkbox" />
<RadioButton Content="this is first radio button" Style="{DynamicResource MyRadioButton}"/>
<RadioButton Content="this is Second radio button" Style="{DynamicResource …Run Code Online (Sandbox Code Playgroud) CheckBox当我根据给定条件选中复选框时,我想更改按钮图标/图像。在这里,我正在使用 MSQS,如果选中 ANSWER Correct 则更改文本框的图像,类似地,当 Answer check false 然后也更改图像时,我已将图像保存在 drawable 中,请任何人告诉我这是怎么可能的。当 Checkbox 选中一次时,不应再次选中或取消选中它。提前感谢谁会帮助我。
public void onCheckboxClicked(View view) {
switch(view.getId()) {
case R.id.chk_ans1ID:
ans_2.setChecked(false);
ans_3.setChecked(false);
ans_4.setChecked(false);
ans_2.setEnabled(false);
ans_3.setEnabled(false);
ans_4.setEnabled(false);
if (QuizActivity.op1.equalsIgnoreCase(QuizActivity.ans)) {
correct++;
} else if (QuizActivity.op2.equalsIgnoreCase(QuizActivity.ans)) {
ans_2.setChecked(true);
incorrect++;
} else if (QuizActivity.op3.equalsIgnoreCase(QuizActivity.ans)) {
ans_3.setChecked(true);
incorrect++;
} else if (QuizActivity.op4.equalsIgnoreCase(QuizActivity.ans)) {
ans_4.setChecked(true);
incorrect++;
} else {
Toast.makeText(QuizActivity.this, "No Answer Match!", Toast.LENGTH_LONG).show();
Toast.makeText(QuizActivity.this, "answer= "+ans, Toast.LENGTH_LONG).show();
}
break;
case R.id.chk_ans2ID:
ans_1.setChecked(false);
ans_3.setChecked(false);
ans_4.setChecked(false);
ans_1.setEnabled(false);
ans_3.setEnabled(false);
ans_4.setEnabled(false);
if (QuizActivity.op2.equalsIgnoreCase(QuizActivity.ans)) {
correct++; …Run Code Online (Sandbox Code Playgroud) 我有一个 ExtJS 网格,它有一个用于(远程)分页的 PagingToolbar,以及一个定义为的复选框列:
{
dataIndex : 'selected',
xtype: 'checkcolumn',
width : 60
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我选中一个框然后向前和向后翻页,则不会保存复选框状态 - 所有复选框都未选中。
我想因为商店只包含当前页面的数据(来自服务器),我需要某种方式来存储不在当前数据页面中的行的状态,然后在我返回到该页面时恢复复选框。
是否有最佳实践或在分页时将复选框状态存储在商店中的示例?
我做的名单checkbox上我与itens adapter和我fragment对列表的顶部,"全选",并在列表中的底部有一个复选框textView"X Itens选择"加一个button.
我的问题1是如何获得这个"x":检查了多少个复选框的计数,因为它们已打开Adapter且TextView打开Fragment,我无法设置它Adapter.为了得到这个,我在setOnCheckedChangeListener复选框列表中使用了一个.我试图通过很多方法从适配器获取Fragment,但没有成功.发送上构造,从viewHolder获得,从得到getSupportFragmentManager(),getFragments(),getFragmentById,getFragmentByTag.我也试过了FragmentObserver,但它没有用.
问题2:所以我试图Adapter用所有选中的Itens 列出一个列表,但是我需要发送它Fragment来管理它.另外,我无法从Adapteron Fragment(on onCreateView)获得它.
有人可以帮忙吗?
我的Adapter.java onBindViewHolder:
@Override
public void onBindViewHolder(final PedidoItemRefugadoViewHolder holder, final int position) {
//pedidoItem is each object from the list
final PedidoItem pedidoItem = itensRefugados.get(position);
//checkCadaItemRefugado is each checkbox from Adapter
holder.checkCadaItemRefugado.setText(pedidoItem.getItemPedidoObservacao(context));
holder.checkCadaItemRefugado.setOnCheckedChangeListener(new …Run Code Online (Sandbox Code Playgroud) 我试图找到解决此问题的任何方法,但没有成功。我只找到了不适用于WPF的WinForms解决方案。
我有一个简单的表格,上面有一些复选框。我想知道选中了哪些复选框。我唯一知道的方法是为每个复选框创建一个方法,例如
"Checkbox1_Checked(object sender, RoutedEventArgs e)"
Run Code Online (Sandbox Code Playgroud)
并在列表中添加复选框的名称(如果未选中该复选框,则将其从列表中删除)。
还有其他方法可以获取所有选中的复选框吗?就像是
foreach (var cb in this.Controls)
{
if (cb is Checkbox && cb.IsCheked()) // blablabla
}
Run Code Online (Sandbox Code Playgroud)