private void button_Click(object sender, RoutedEventArgs e)
        {
            string nameText = this.textBox1.Text;
            string schoolText = this.textBox.Text;

            // school変数に学校名を設定
            School school = new School();
            school.Name = schoolText;

            // データベースにschoolを登録
            this.context.School.InsertOnSubmit(school);
            this.context.SubmitChanges();

            // student変数に氏名を設定
            Student student = new Student();
            student.Name = nameText;
            student.SchoolId = school.Id;

            // データベースにstudentを登録
            this.context.Student.InsertOnSubmit(student);
            this.context.SubmitChanges();

            // 画面表示用コレクションにschoolを登録
            this.observableStudent.Add(student);
            this.dataGrid.ItemsSource = this.observableStudent;
        }
Beispiel #2
0
        //List<Student> _stulist;
        public MainWindow()
        {
            InitializeComponent();

            _stu = new Student() { Name = "qhk" };

            //Binding binding = new Binding();
            //binding.Source = _stu;
            //binding.Path = new PropertyPath("Name");
            //BindingOperations.SetBinding(textBoxName, TextBox.TextProperty, binding);

            textBoxName.SetBinding(TextBox.TextProperty, new Binding("Name.Length"){Source = _stu, Mode=BindingMode.OneWay});

            _stulist = new ObservableCollection<Student>()
            //_stulist = new List<Student>()
            {
                new Student() {Name="Tim0", Age = 20, Id = 0},
                new Student() {Name="Tim1", Age = 21, Id = 1},
                new Student() {Name="Tim2", Age = 22, Id = 2},
                new Student() {Name="Tim3", Age = 23, Id = 3},
            };

            lbStudents.ItemsSource = _stulist;
            //lbStudents.DisplayMemberPath = "Name";
            //lbStudents.ItemTemplate = new DataTemplate(

            tbStuId.SetBinding(TextBox.TextProperty, new Binding("SelectedItem.Id") { Source = lbStudents,Mode=BindingMode.TwoWay });
        }
 partial void DeleteStudent(Student instance);
 partial void UpdateStudent(Student instance);
 partial void InsertStudent(Student instance);
		private void detach_Student(Student entity)
		{
			this.SendPropertyChanging();
			entity.School = null;
		}
		private void attach_Student(Student entity)
		{
			this.SendPropertyChanging();
			entity.School = this;
		}