2.Xaml绑定选择结果
Pick a color from below list Orange Green Blue Gray LightGray Red
3.绑定ListBox.Templete 模板内容
////// List3.xaml 的交互逻辑/// public partial class List3 : Window{ public List3() { InitializeComponent(); listBox.ItemsSource = new List() { new UserItem(1,"张三",true), new UserItem(2,"李四",false), new UserItem(3,"王五",false), new UserItem(4,"赵六",true) }; } private void Button_MouseDoubleClick(object sender, MouseButtonEventArgs e) { Button btn = sender as Button; if (btn != null) { Image img = btn.FindName("img") as Image; if (img != null) { MessageBox.Show(img.Source.ToString()); } } }}public class UserItem{ public UserItem(int ID, string Name, bool IsActive) { this.ID = ID; this.Name = Name; this.IsActive = IsActive; } public int ID { get; set; } public string Name { get; set; } public bool IsActive { get; set; } public string BackGround { get { return this.IsActive ? "/images/1.jpg" : "/images/2.jpg"; } }}
Xaml定义
显示结果: