2016-08-06 9 views
0

I持っているリストボックスにバインドされたテキストボックス:リストボックスがバインドされているリストにテキストボックスの内容を追加しますバインドチェーン、観察可能なコレクションが動作していない

<TextBox Text="{Binding ElementName=PasswordsBox, Path=SelectedItem, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Grid.Column="1" Grid.Row="1" Name="PasswordBox"/> 
<ListBox ItemsSource="{Binding Processor.Passwords,ValidatesOnDataErrors=True,Mode=TwoWay}" Name="PasswordsBox" Grid.Row="1"/> 

とボタン、 To:

<Button Grid.Row="1" Grid.Column="3" Command="{Binding AddPasswordCommand}" CommandParameter="{Binding Text, ElementName=PasswordBox}">+</Button> 

コマンドは次のように定義されます。ここでは

_addPasswordCommand = new DelegateCommand<string>((newPass) => Processor.Passwords.Add(newPass)); 

は「パですモデルからの剣のコレクション

public ObservableCollection<string> Passwords 
    { 
     get 
     { 
      return _passwords; 
     } 
     set 
     { 
      if (_passwords != value) 
      { 
       _passwords = value; 
       OnPropertyChanged("Passwords"); 
      } 
     } 
    } 

しかし、私もテキストボックスに何かを入力することはできません。コマンドで空の要素を追加して選択すると、編集できません。

答えて

0

あなたのテキストボックスには、選択した項目は、タイプのパスワードであるため、この

<TextBox Text="{Binding ElementName=PasswordsBox, Path=SelectedItem.Password, Mode=TwoWay}" Grid.Column="1" Grid.Row="1" Name="PasswordBox"/> 

のようなリストボックスのSelectedItem、何かのプロパティにバインドする必要があり、私はその後、パスワードのクラスはそれでtextプロパティを持っていると仮定します。

+0

パスワードプロパティはObservableCollection です。注:私のアプリケーションの場合、これは秘密の問題ではありません;) – R3turnz

関連する問題