使用wpf的复选框 [英] checkboxlist using wpf

查看:98
本文介绍了使用wpf的复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要Wpf中的复选框
使用xaml我在设计中获得了核对清单,但我不知道如何在代码中使用它,这是我的xaml代码
< listbox x:name ="listExtraSkills" itemssource ="{Binding CheckList}" grid.column ="1" grid.row ="6" height ="50" xmlns:x =#unknown"> < listbox.itemtemplate> < datatemplate>
< checkbox name ="chkitems" content ="{Binding TheText}" ischecked ="{Binding IsSelected}">

i want checkboxlist in Wpf
using xaml i got the checkboxlist in design but i don''t know how to use this in code this is my xaml code
<listbox x:name="listExtraSkills" itemssource="{Binding CheckList}" grid.column="1" grid.row="6" height="50" xmlns:x="#unknown"> <listbox.itemtemplate> <datatemplate>
<checkbox name="chkitems" content="{Binding TheText}" ischecked="{Binding IsSelected }">

推荐答案

嗨.
首先创建实体并将其绑定到您的UI.
假设您创建这样的模型:
Hi.
First of all create and bind entity to your UI.
Let assume that you create model like this:
public class MyModel
{
public bool IsChecked{get;set;}
public string Name{get;set;}
}




为项目的listBox模板定义:




Define for your listBox template for item:

<listbox x:name="lb1" xmlns:x="#unknown">
         ScrollViewer.VerticalScrollBarVisibility="Visible"> 
    <listbox.itemtemplate> 
      <datatemplate> 
        <stackpanel orientation="Horizontal"> 
          <checkbox ischecked="{Binding IsChecked, Mode=TwoWay}" /> 
          <textblock text="{Binding Name}" /> 
        </stackpanel> 
      </datatemplate> 
    </listbox.itemtemplate> 
</listbox>




代码中的Tanh只需绑定List< mymodel>到列表框:




Tanh in your code just bind List<mymodel> to listbox:

lb1.ItemSource=list; //where list is reference to your list of MyModel.


这篇关于使用wpf的复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆