简要介绍

目前为止最强WPF进阶教程WPF进阶教程
现阶段对部分概念依旧不怎么理解,但是此教程能跟着解决部分自制控件的问题

解决方案

<Window x:Class="WpfApp6.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"xmlns:local="clr-namespace:WpfApp6"mc:Ignorable="d"Title="MainWindow" Height="450" Width="800"><Window.Resources><Style x:Key="checkboxListStyle" TargetType="{x:Type ListBox}"><Setter Property="SelectionMode" Value="Multiple"></Setter><Setter  Property="ItemContainerStyle" ><Setter.Value><Style TargetType="{x:Type ListBoxItem}"><Setter Property="Margin" Value="2"></Setter><Setter Property="Template"><Setter.Value ><ControlTemplate  TargetType="{x:Type ListBoxItem}"><CheckBox IsChecked="{Binding Path=IsSelected,RelativeSource={RelativeSource TemplatedParent},Mode=TwoWay}"><ContentPresenter></ContentPresenter></CheckBox></ControlTemplate></Setter.Value></Setter></Style></Setter.Value></Setter></Style></Window.Resources><Grid><Grid.RowDefinitions><RowDefinition></RowDefinition><RowDefinition Height="auto"></RowDefinition></Grid.RowDefinitions><ListBox Style="{StaticResource checkboxListStyle}" Name="listProducts" ></ListBox><Button Grid.Row="1" Name="btn"  Click="btn_Click">get Selected item</Button></Grid>
</Window>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;namespace WpfApp6
{/// <summary>/// MainWindow.xaml 的交互逻辑/// </summary>public partial class MainWindow : Window{public MainWindow(){InitializeComponent();List<student> students = new List<student>{new student(){ModelName="校长"},new student(){ModelName="小王"}};this.listProducts.ItemsSource = students;this.listProducts.DisplayMemberPath = "ModelName";}private void btn_Click(object sender, RoutedEventArgs e){if (listProducts.SelectedItems.Count > 0){string items = "you Selected:";foreach (student item in listProducts.SelectedItems){items += "\n" + item.ModelName;}MessageBox.Show(items);}}private void allbtn_Click(object sender, RoutedEventArgs e){this.listProducts.SelectAll();}private void clearbtn_Click(object sender, RoutedEventArgs e){this.listProducts.UnselectAll();}public class student{public string ModelName { get; set; }public bool? IsSelected { get; set; }}}
}

listbox +CheckBox相关推荐

  1. NSIS 的 Modern UI 教程(二)

    NSIS 的 Modern UI 教程(二) [ 2008-02-24 20:22:20 | 作者: 陈敏毅 ] http://chenmy.hanzify.org/article.asp?id=51 ...

  2. python居中对齐代码end_Python tkinter.END属性代码示例

    本文整理汇总了Python中tkinter.END属性的典型用法代码示例.如果您正苦于以下问题:Python tkinter.END属性的具体用法?Python tkinter.END怎么用?Pyth ...

  3. DevExpress v18.1新版亮点——WPF篇(五)

    用户界面套包DevExpress v18.1日前终于正式发布,本站将以连载的形式为大家介绍各版本新增内容.本文将介绍了DevExpress WPF v18.1 的新功能,快来下载试用新版本!点击下载& ...

  4. vba数据类型,运算符,内置函数,循环判断语句,窗体控件

    文章目录 VBA基本数据类型 示例代码 声明常量,运算符和表达式 内置函数 代码 可视化编程 判断语句 循环语句 窗体控件,窗体的加载卸载 listbox,checkbox,combobox VBA基 ...

  5. [知识库分享系列] 二、.NET(ASP.NET)

    最近时间又有了新的想法,当我用新的眼光在整理一些很老的知识库时,发现很多东西都已经过时,或者是很基础很零碎的知识点.如果分享出去大家不看倒好,更担心的是会误人子弟,但为了保证此系列的完整,还是选择分享 ...

  6. NSIS MUI教程

    NSIS 2.0 版本支持定制的用户界面.所谓的 Modern UI(下称 MUI) 就是一种模仿最新的 Windows 界面风格的界面系统.MUI 改变了 NSIS 脚本的编写习惯,它使用 NSIS ...

  7. ABAP CHECKBOX 和LISTBOX使用指南

    1.什么是checkbox: 就是一个复选框,可以用like或者type来定义,为1个字符型变量.它是parameter的一个选项,parameter xxx as checkbox就可以在选择屏幕上 ...

  8. ListBox控件、CheckBox控件的多选功能

    我们在使用控件的时候,经常会用到ListBox控件.CheckBox控件来进行选择 1.ListBox控件 我们经常会在网页或程序中看到这样的功能: 将一个ListBox控件里的选择项添加到另一个Li ...

  9. 稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox

    [索引页] [源码下载] 稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 详解ListBox 作者:webabcd 介绍 Silverlight 2.0 详解DataG ...

最新文章

  1. 少年郎,你为什么没有对象?是缺点“土味情话”
  2. Myeclipse优化设置,加速你的开发武器
  3. EJB3与Spring的集成
  4. 程序一直吐司提示获取缓存记录失败以及吐司显示set Alias success
  5. Cutting Bamboos(牛客多校第九场H主席树+二分+思维)
  6. Java Secret:加载和卸载静态字段
  7. js使用base64 上传图片解决iOS手机竖屏拍摄图片发生旋转问题
  8. pycharm不认识numpy?_深度学习(CV方向)入坑不完全指南
  9. 常用MIME类型(Flv,Mp4的mime类型设置)(转载)
  10. Powershell 美化,FluentTerminal.Package_0.6.1.0_Test安装设置及卸载教程
  11. 测试山石防火墙 接口中 逆向路由 设置与urpf是否有关
  12. Excel中排序和筛选
  13. R、冗余分析(RDA)、ggplot2、置信椭圆
  14. html5游戏修改,Duang! Html5游戏调试神器全新出炉!- Cocos DevTools
  15. 判断当前时间是否是法定节假日或工作日
  16. 计算机系微电子专业大学排名,2017微电子专业大学排名
  17. 项目可交付成果的质量管理该怎么做?
  18. fiddler配置手机连接电脑抓取手机APP的包
  19. HMS Core Discovery直播预告 | AI画质增强 ,开启超清视界
  20. 详解JVM类加载机制

热门文章

  1. Logistic回归模型和Zeppelin简单使用
  2. $.get()的使用
  3. 一个让Flex代码也能自动套用格式的插件 转
  4. R和Rstudio中包的安装、加载和查看等操作
  5. (简单)华为畅玩7C LND-AL30的Usb调试模式在哪里开启的步骤
  6. java连接redis哨兵模式
  7. JVM成神之路-Java对象模型
  8. 箭头随着手指滑动而旋转(一)
  9. leftTicket(余票信息查询)
  10. python中def func(*args, **kwargs)