ObservableCollection を ListBox にバインドしようとしています。デバッグからの出力にはバインディング エラーは表示されませんが、何らかの理由で機能しません。
xaml:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:nwsfeed"
x:Class="nwsfeed.MainWindow"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
x:Name="Window">
<ListBox x:Name="listBoxChannels"
ItemsSource="{Binding ElementName=Window, Path=App.ActiveProfile.Feeds}"
DisplayMemberPath="Title"/>
</Window>
コード:
public partial class MainWindow : Window {
public NwsfeedApp App { get; set; }
// ..
}
public sealed class NwsfeedApp {
public UserProfile ActiveProfile { get; set; }
//..
}
public class UserProfile {
private ObservableCollection<RSSFeed> feeds;
public ObservableCollection<RSSFeed> Feeds { get { return feeds; } }
//..
}
edit : 問題は、ObservableCollection を MainWindow のパブリック プロパティとして持っていて、それを次のようにバインドすると、機能することです。
ItemsSource="{Binding ElementName=Window, Path=Items, Mode=OneWay}"
しかし、私がこれを行うと、そうではありません:
ItemsSource="{Binding ElementName=Window, Path=App.ActiveProfile.Feeds, Mode=OneWay}"
edit2 App、ActiveProfile、および Feeds プロパティに INotifyPropertyChanged を実装しました。ListBox は、.Items.Refresh() を呼び出さない限り、コレクションの変更を反映しません。
助言がありますか?ありがとう。