1 2 3 4 5 6 7 8 9 10 11 12 13 | namespace Demo10 { public class Student { private string name; public string Name { get { return name; } set { name = value; } } } } |
<Window x:Class="Demo10.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <StackPanel> <TextBlock Margin="5" Text="Student Name:"/> <TextBox Margin="5" x:Name="txtName"/> <TextBlock Margin="5" Text="Student List:"/> <ListBox Margin="5" x:Name="lsbList"/> </StackPanel> </Window>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | using System.Collections.Generic; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; namespace Demo10 { /// <summary> /// MainWindow.xaml 的交互逻辑 /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); List<Student> stuList = new List<Student>() { new Student(){Name = "Tim" }, new Student(){Name = "Tom" }, new Student(){Name = "JIM" }, new Student(){Name = "Kite" }, new Student(){Name = "quanquan" }, }; this .lsbList.ItemsSource = stuList; this .lsbList.DisplayMemberPath = "Name" ; Binding binding = new Binding( "SelectedItem.Name" ) { Source= this .lsbList}; this .txtName.SetBinding(TextBox.TextProperty,binding); } } } |
博客内容主要用于日常学习记录,内容比较随意,如有问题,还需谅解!!!
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步