사용자 지정 목록 상자에서 볼 수있는 ObservableCollection이 있습니다. 나는ObservableCollection이 목록보기를 업데이트하지 않습니다.
<ListBox x:Name="listBox1" >
<ListBox.ItemTemplate >
<DataTemplate >
<StackPanel Width="400" Margin="20" >
<Button x:Name="pic" Tag="{Binding Id}">
<Button.Template>
<ControlTemplate>
<TextBlock Text="{Binding title}" TextWrapping="Wrap" FontFamily="Arial" FontSize="28" Tag="{Binding Id}"/>
</ControlTemplate>
</Button.Template>
</Button>
<TextBlock Text="{Binding pudate}" TextWrapping="Wrap" FontSize="24"/>
<Image Source="{Binding source_icon}" Width="100" Height="60"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
주
public class lbl
{
public ObservableCollection<feed> ModifiedItems
= new ObservableCollection<feed>();
public lbl()
{
InitializeComponent();
listBox1.ItemsSource = ModifiedItems ;
}
public void update(object sender, EventArgs e)
{
var x = ModifiedItems.Last();
listBox1.Items.Add(x);
}
}
public class feed
{
public int ID { get; set; }
public int source_id { get; set; }
public string title { get; set; }
public string source_icon { get; set; }
public string url { get; set; }
public string pudate { get; set; }
}
아래 XAML 사용할 수있는 코드의
부품을 새 피드를 삽입하거나 ObservableCollection에에서 피드를 제거 같이 적용 변경에 따라보기를 업데이트 할 목록 상자가 필요합니다 : 이것은 코드의 일부가 아닙니다. "읽기 전용 컬렉션에서 지원되지 않는 작업"항목을 추가하려고하면 오류가 발생합니다.
여기에 게시 된 솔루션을 시도한 Implementing CollectionChanged과 여전히 같은 오류가 발생합니다.
어떤 도움 사전