將文本框綁定到工作站對象的值時出現問題。值正確顯示,但是當我編輯屏幕上的值源不會更新。我究竟做錯了什麼?更改UI時未更新源
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>
如果你的意思是在代碼上一站的變化不會反映在UI然後根據@avanek說,它INotifyPropertyChanged的。如果不是,請同時顯示XAML – kaj 2012-03-02 13:30:20
我已經插入了我的XAML,但沒有什麼值得注意的... – TheJoeIaut 2012-03-02 13:35:27
但是哪種方式無法使用? 1.屏幕上的更改未反映在代碼中或2.代碼中的更改未反映在屏幕上? – kaj 2012-03-02 14:11:52