0

1つの監視可能なコレクションをSilverlightの1つのリストボックスにバインドしました。リストボックスの1つのアイテムをクリックし、[削除]ボタンをクリックすると、mvvm.iを使用してlinqを使用せずにその特定のアイテムをリストボックスから削除する方法がリストボックスitemidに渡されます。

 <ListBox   ItemsSource="{Binding School1,Mode=TwoWay}" DisplayMemberPath="SchoolName"  Name="listBox1"  >
<Button Content="Delete" Command="{Binding deletecommand}" CommandParameter="{Binding Path=SelectedItem.ID,ElementName=listBox1}"   Name="button2" />

したがって、監視可能なコレクションから特定のアイテムを削除するためのコードは何ですか

public void delete(object parameter)
{
School1.Remove(...)
}
4

1 に答える 1

0

ListBox のSelectedItemをプロパティにバインドし、それを Remove() で使用します。

 <ListBox ItemsSource="{Binding School1, Mode=TwoWay}" 
          DisplayMemberPath="SchoolName"  
          SelectedItem={Binding SelectedSchool}
          Name="listBox1"  
          />


public void delete(object parameter)
{
    if (SelectedSchool != null)
        School1.Remove(SelectedSchool);
}

また、あなたの質問は多少重複していることにも注意してください: Clearing selecteditem of listbox (これはオブジェクトのコレクションにバインドされています) with MVVM

于 2012-11-12T06:11:27.220 に答える