【发布时间】:2011-10-28 02:09:42
【问题描述】:
我有一个可在自定义列表框中查看的 ObservableCollection。我需要列表框根据应用的更改更新视图,例如插入新提要或从 ObservableCollection 中删除提要
下面有部分代码
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
<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>
注意:这不是代码的一部分。 尝试添加项目“只读集合不支持操作”时,它给了我错误。
我尝试了Implementing CollectionChanged 此处发布的解决方案,但仍然出现同样的错误。
任何帮助,请提前致谢
【问题讨论】:
标签: windows-phone-7