有代码有J8:

UI

<UserControl x:Class="UnitViews.UserListUV"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
> <StackPanel Orientation="Vertical">
<ListBox x:Name="Lst" ItemsSource="{Binding Path=UserList}" BorderBrush="Transparent"> <i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding SelectionChangedCmd}"
CommandParameter="{Binding ElementName=Lst}" />
</i:EventTrigger>
</i:Interaction.Triggers> <ListBox.ItemTemplate>
<DataTemplate>
<Grid Height="30">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="25"/>
<ColumnDefinition Width="220"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Image Source="{Binding Path=StrUrlPath}" Style="{StaticResource UserStatusIcon}" Grid.Column="0" />
<TextBlock Text="{Binding Path=StrReMarkName}" Margin="5 0" FontSize="18" Grid.Column="1"></TextBlock>
<Image Source="{Binding Path=CmdIcon}" Style="{StaticResource UserCmdIcon}" Grid.Column="2" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel> </UserControl>

VM:

DelegateCommand<ListBox> _SelectionChangedCmd = null;
public DelegateCommand<ListBox> SelectionChangedCmd
{
get
{
if (this._SelectionChangedCmd == null)
{
this._SelectionChangedCmd = new DelegateCommand<ListBox>(SelectionChanged);
} return this._SelectionChangedCmd;
}
}
void SelectionChanged(ListBox lst)
{
SelectedUser = lst.SelectedItem as User;
}
//这个就是选中项啦。User是自定义类
public User SelectedUser { get; set; }

WPF学习笔记:获取ListBox的选中项的更多相关文章

  1. WPF学习笔记——设置ListBox选中项的背景颜色

    ListBox的选中项,在我这个WIN7里面,是亮蓝色,颜色是如此之浓厚,差不多遮盖了前景的字体! 太不协调了.可是怎么设置呢?设置触发器,又是IsMouseOver,又是IsFocused,在谷歌里 ...

  2. Android 学习笔记---获取RadioGroup的选定值

    1,获取RadioGroup控件: RadioGroup radioGroup = (RadioGroup)findViewById(R.id.myRadioGroup); 2,获取RadioButt ...

  3. WPF学习笔记-用Expression Design制作矢量图然后导出为XAML

    WPF学习笔记-用Expression Design制作矢量图然后导出为XAML 第一次用Windows live writer写东西,感觉不错,哈哈~~ 1.在白纸上完全凭感觉,想象来画图难度很大, ...

  4. WPF 学习笔记-在WPF下创建托盘图标

    原文:WPF 学习笔记-在WPF下创建托盘图标 首先需要在项目中引用System.Windows.Forms,System.Drawing; using System; using System.Co ...

  5. WPF 学习笔记-设置属性使窗口不可改变大小

    原文:WPF 学习笔记-设置属性使窗口不可改变大小 调整Windows下的ResizeMode属性: ResizeMode = NoResize Resize属性是控制Windows是否可以改变大小, ...

  6. WPF学习笔记(8):DataGrid单元格数字为空时避免验证问题的解决

    原文:WPF学习笔记(8):DataGrid单元格数字为空时避免验证问题的解决 如下图,在凭证编辑窗体中,有的单元格不需要数字,但如果录入数字后再删除,会触发数字验证,单元格显示红色框线,导致不能执行 ...

  7. wpf中ListBox的选中项与ComboBox间的绑定

    产品类: public class Product:NotificationObject { private int productID; public int ProductID { get { r ...

  8. WPF TreeView 虚拟化-设置滚动到选中项

    前言 列表滚动到具体的数据项? ListBox提供了简易快捷的滚动定位函数ScrollIntoView. TreeView树状结构列表,则没有此类方法,无法与ListBox一样,直接设置滚动到具体的数 ...

  9. 【WPF学习笔记】之如何把数据库里的值读取出来然后显示在页面上:动画系列之(六)(评论处有学习资料及源码)

    (应博友们的需要,在文章评论处有源码链接地址,以及WPF学习资料.工具等,希望对大家有所帮助) ...... 承接系列五 上一节讲了,已经把数据保存到数据库并且删除数据,本讲是把已经存在的数据从数据库 ...

随机推荐

  1. linux环境下为php7装phpredis扩展

    phpredis在php7.php5下都有不同的版本,装岔了可能会编译报错,所以在安装之前请先看下自己的php是啥版本. 我的redis装的是redis3.2.3版本. 用phpinfo()查看安装的 ...

  2. HiveServer2后台运行

    nohup hive --service hiveserver2 & 或者直接: nohup hiveserver2 &

  3. Flask框架 之重定向、cookie和session

    一.URL重定向(redirect) @app.route("/login") def login(): # 使用url_for函数通过视图函数的名字找到url路径 url = u ...

  4. 06Oracle Database 数据类型

    Oracle Database 数据类型 字符型 char(n)最大2000个字节 定长 nchar(n)最大2000个字节 变长 varchar2(n) 最大4000个字节 变长 nvarchar2 ...

  5. 关于ORB SLAM2资源整理(持续更新)

    ORB SLAM2源码讲解(吴博) https://www.youtube.com/watch?v=2GVE7FTW7AU 泡泡机器人视频整理: http://space.bilibili.com/3 ...

  6. openpyxl操作excel文件

    https://blog.csdn.net/hunter_wyh/article/details/78498323

  7. python之cookbook-day02

    第一章:数据结构和算法 1.2 解压可迭代对象赋值给多个变量 问题: 如果一个可迭代对象的元素个数超过变量个数时,会抛出一个 ValueError .那么 怎样才能从这个可迭代对象中解压出 N 个元素 ...

  8. journals in Fluid Dynamics

    annual review of fluid mechanicsjournal of fluid mechanicsphysics of fluidjournal of flow and struct ...

  9. BZOJ 1666 USACO 2006 Oct. 奶牛的数字游戏

    直接模拟2333 #include<cstdio> #include<algorithm> using namespace std; int n,ans; void read( ...

  10. phpcms 搭建宣传网站首页

    1 .修改后台提交的表单信息展示: 文件路径: phpcms\modules\formguide\template\formguide_info_list.tpl.php function getQu ...