私のMainWindowには、バインドごとにリストボックスに表示されるObservableCollectionがあります。パスが使用されているとバインディングがリフレッシュされない
私のコレクションを更新すると、リストにその変更が表示されます。
これは動作します:
public ObservableCollection<double> arr = new ObservableCollection<double>();
public MainWindow()
{
arr.Add(1.1);
arr.Add(2.2);
testlist.DataContext = arr;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
arr[0] += 1.0;
}
<ListBox Name="testlist" ItemsSource="{Binding}"></ListBox>
このバージョンではありません動作します。
public ObservableCollection<double> arr = new ObservableCollection<double>();
public MainWindow()
{
arr.Add(1.1);
arr.Add(2.2);
testlist.DataContext = this;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
arr[0] += 1.0;
}
<ListBox Name="testlist" ItemsSource="{Binding Path=arr}"></ListBox>
あなたはなぜ私に言うことはできますか? このをDataContextとして提供したいと思います。私のダイアログには他にも多くのプロパティが表示され、個々のコントロールごとにDataContextを設定する必要がない場合は便利です。