WPF Binding Path妙用代码实现

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;


namespace XamlTest
{
    /// <summary>
    /// Interaction logic for Window10.xaml
    /// </summary>
    public partial class Window10 : Window
    {
        public Window10()
        {
            InitializeComponent();
            List<string> lst = new List<string>() {"zhangsan","lisi","wangwu"};
            this.txt1.SetBinding(TextBox.TextProperty,new Binding("/"){Source=lst, Mode= BindingMode.OneWay});
            this.txt2.SetBinding(TextBox.TextProperty, new Binding("/Length") { Source = lst, Mode = BindingMode.OneWay });
            this.txt3.SetBinding(TextBox.TextProperty, new Binding("/[3]") { Source = lst, Mode = BindingMode.OneWay });


        }
    }
}
posted @ 2018-07-06 08:38  dxm809  阅读(241)  评论(0编辑  收藏  举报