2012-03-02 23 views
1

ステーションオブジェクトの値にテキストボックスをバインドするときに問題があります。値は正しく表示されますが、画面上の値を編集するとソースは更新されません。何が間違っているのですか?UIの変更時にソースが更新されない

 <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> 

+0

をあなたは@avanekが言うように、それがINotifyPropertyChangedのだUIに反映されていないコードでステーションの変更を意味する場合。そうでない場合は、XAMLを表示してください – kaj

+0

私はXAMLを挿入しましたが、実際にはあまり見ていません... – TheJoeIaut

+0

しかし、どのようにラウンドが機能していませんか? 1.コードに反映されていない画面の変更または2.画面に反映されていないコードの変更? – kaj

答えて

2

はあなたのStationクラスにimplementing INotifyPropertyChangedを試してみました:

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); 
     } 
} 

マイステーションクラスは重要なものはありません私のXAMLで

class Station 
{ 
    public int Id { get; set; } 
    public String Name { get; set; } 
    public int Value { get; set; } 

} 

のように見えますか?また、foreachループの先頭にあるStationsコレクションに使用されているタイプは何ですか?

1

INotifyPropertyChangedインターフェイスをStationクラスに実装する必要があります。だから、あなたのStationクラスは次のようになります。

public class Station : INotifyPropertyChanged 
{ 
    private int id; 
    private String name; 
    private int value; 

    public int Id 
    { 
     get { return this.id; } 
     set 
     { 
      this.id = value; 
      NotifyPropertyChanged("Id"); 
     } 
    } 

    public String Name 
    { 
     get { return this.name; } 
     set 
     { 
      this.name = value; 
      NotifyPropertyChanged("Name"); 
     } 
    } 

    public int Value 
    { 
     get { return this.value; } 
     set 
     { 
      this.value = value; 
      NotifyPropertyChanged("Value"); 
     } 
    } 

    public event PropertyChangedEventHandler PropertyChanged; 

    private void NotifyPropertyChanged(String info) 
    { 
     if (PropertyChanged != null) 
     { 
      PropertyChanged(this, new PropertyChangedEventArgs(info)); 
     } 
    } 

} 
+0

ありがとう、しかしこれで私の問題はまだ解決しませんでした。私はあなたが私の問題を間違っていると思う:UIの変更は、ソースに反映されず、別の方法ではありません。 – TheJoeIaut

+0

通常のテキストボックスで試してみましたが、正常に動作しています。 – Amit

関連する問題