WPF学习笔记:获取ListBox的选中项
来源:互联网 发布:js 不等于空字符串 编辑:程序博客网 时间:2024/06/05 01:53
有代码有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; }
0 0
- WPF学习笔记:获取ListBox的选中项
- WPF学习笔记——设置ListBox选中项的背景颜色
- WPF ListBox获取选中内容
- Wpf listbox修改选中的项样式
- WPF,去掉ListBox的右键选中项
- wpf ListBox获取选中内容 ComboBox
- 获取ListBox中所有选中的项
- wpf listbox 选中项 上移下移
- ListBox获取、设置选中项用法
- WPF中确保显示ListBox选中的Item
- wpf ListBox 选中项背景颜色的修改
- WPF ListBox控件学习
- ListBox 中获得选中项的方法
- 设置 ListBox 选中项的背景颜色
- 设置ListBox选中项的背景颜色
- WPF学习笔记——ListBox用ItemsSource绑定数据源
- WPF学习笔记——ListBox用ItemsSource绑定数据源
- Wpf:获取当前选中行的某列值
- HTML基础
- Android ActionBar完全解析,使用官方推荐的最佳导航栏(上)
- linux环境使用Eclipse开发Android应用程序时使用真机调试方式
- 什么是REST风格
- 网页选项卡
- WPF学习笔记:获取ListBox的选中项
- uva 11995 I Can Guess the Data Structure!
- Android ActionBar完全解析,使用官方推荐的最佳导航栏(下)
- UVa 10719 - Quotient Polynomial
- 现在的我很幸福
- MySQL引擎
- SGU 102 prime水题
- Linux socket编程介绍
- Vim的使用