У меня проблема при привязке текстового поля к значению объекта станции. Значения отображаются правильно, но когда я редактирую значения на экране, Источник не обновляется. Что я делаю не так?
public LineControl(ArrayList cells)
{
InitializeComponent();
this.cells = cells;
foreach (Cell c in cells)
{
AccordionItem aci = new AccordionItem();
StackPanel sp = new StackPanel();
aci.Content = sp;
DataGrid dg = new DataGrid();
if(c.Stations!=null)
foreach (Station s in c.Stations)
{
TextBox t = new TextBox();
t.DataContext = s;
Binding binding = new Binding();
binding.Mode = BindingMode.TwoWay;
binding.Source = s;
binding.Path = new PropertyPath("Value");
binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
t.SetBinding(TextBox.TextProperty, binding);
//t.TextChanged += new TextChangedEventHandler(t_TextChanged);
sp.Children.Add(t);
}
acc.Items.Add(aci);
}
}
Мой класс станции выглядит как
class Station
{
public int Id { get; set; }
public String Name { get; set; }
public int Value { get; set; }
}
В моем XAML нет ничего значительного:
<UserControl x:Class="Knowles_ShiftreportEditor.LineControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:toolkit="clr- namespace:System.Windows.Controls;assembly=System.Windows.Controls.Layout.Toolkit"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="100">
<Grid>
<toolkit:Accordion Width="100" Name="acc" SelectionMode="One" Loaded="acc_Loaded">
</toolkit:Accordion>
</Grid>