ListBox绑定的行为与TextBlock绑定不同

时间:2012-08-24 16:11:29

标签: wpf

以下是触发PropertyChanged的属性:

public override List<Tag> Tags
{
    get
    {
        return base.Tags;
    }
    set
    {
        if (base.Tags != value) {
            base.Tags = value;
            if (PropertyChanged != null)
            {
                PropertyChanged(this, 
                         new PropertyChangedEventArgs("Tags"));
                PropertyChanged(this, 
                         new PropertyChangedEventArgs("TotalTagPages"));
                PropertyChanged(this, 
                         new PropertyChangedEventArgs("PageHasTags"));
             }
        }

    }
}

当修改CurrentPage.Tags时,此控件正确刷新:

<TextBlock DockPanel.Dock="Bottom" Name="TagHeader" 
    Text="{Binding CurrentPage.Tags,
         Converter={converter:EnumerableToSpacedString}}"    
    Foreground="White" />

更改CurrentPage.Tags时不刷新,但更改CurrentPage本身时会这样做:

<ListBox VerticalAlignment="Top"
   Style="{StaticResource DarkListBox}"  
   ItemTemplate="{StaticResource TagTemplateNoCounts}" 
   ItemsSource="{Binding CurrentPage.Tags}" >
        <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
        <StackPanel Orientation="Horizontal"></StackPanel>  
        </ItemsPanelTemplate>
        </ListBox.ItemsPanel>
</ListBox>

有什么想法吗?

1 个答案:

答案 0 :(得分:2)

看不出有什么理由不起作用(而不是修改列表,这需要INotifyCollectionChanged)...