复选框TwoWay绑定 [英] checkbox TwoWay binding
本文介绍了复选框TwoWay绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的xaml代码:
< ListBox 名称 =" ItemsSource =" 保证金 =" 高度 =" VerticalAlignment =" 居中" >
< ListBox.ItemTemplate >
< DataTemplate >
< 复选框 =" {Binding FilterName,Mode = TwoWay}" / >
< /DataTemplate >
< /ListBox.ItemTemplate >
< /ListBox >
这是.cs文件中的代码
命名空间 ReportsUIScreens
{
公共 部分 类 EditStyle:ChildWindow
{
私有列表< filterHistory> histList;
公共 EditStyle(List< filterHistory> histListLink)
{
InitializeComponent();
histList = histListLink;
此 .ListBox1.ItemsSource = histList;
}
私有 无效 OKButton_Click(对象发件人,RoutedEventArgs e)
{
// 在哪里我要删除
此.DialogResult= true ;
}
......
......
......
}
}
请帮助我...
解决方案
您将需要绑定到选中的复选框属性,并从后面代码中的列表框中删除一个项目.
hi! i have a listbox binded to a list. the list contains checkboxes binded to a field/member of the list. what i want to achieve is that i want to delete the data from list when it''s corresponding checkbox is checked...
here''s my xaml code:
<ListBox Name="ListBox1" ItemsSource="{Binding histList, Mode=OneWay}" Margin="10,10,10,10" Height="197" VerticalAlignment="Center" >
<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox Content="{Binding FilterName, Mode=TwoWay}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
here''s the code in the .cs file
namespace ReportsUIScreens
{
public partial class EditStyle : ChildWindow
{
private List<filterHistory> histList;
public EditStyle(List<filterHistory> histListLink)
{
InitializeComponent();
histList = histListLink;
this.ListBox1.ItemsSource=histList;
}
private void OKButton_Click(object sender, RoutedEventArgs e)
{
//HERE'S WHERE I WANT TO DELETE
this.DialogResult = true;
}
.........
.........
.........
}
}
please help me...
解决方案
You will need to bind to the checkbox checked property and remove an item from the list box in your code behind.
这篇关于复选框TwoWay绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文