欢迎莅临 SUN WU GANG 的园子!!!

世上无难事,只畏有心人。有心之人,即立志之坚午也,志坚则不畏事之不成。

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  470 随笔 :: 0 文章 :: 22 评论 :: 30万 阅读
< 2025年1月 >
29 30 31 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 1
2 3 4 5 6 7 8
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);
        }
    }
}

posted on   sunwugang  阅读(219)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示