代码之家  ›  专栏  ›  技术社区  ›  sudarsanyes

在wpf中最大化窗口后反映的数据源

  •  0
  • sudarsanyes  · 技术社区  · 16 年前

    这真是奇怪。我尝试了一个简单的数据绑定示例程序。我尝试将集合(IList)绑定到列表框。当我改变集合时,列表框只有在我最大化窗口时才会更新。以下是片段,

    <ListBox x:Name="myBirthdaysListBox" ItemsSource="{Binding}">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <UniformGrid>
                    <Label Content="{Binding Name}"></Label>
                    <Label Content="{Binding DateOfBirth}"></Label>
                </UniformGrid>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
    
    public Window1()
    {
        InitializeComponent();
        myCalendar = new List<Calendar>();
        myBirthdaysListBox.DataContext = myCalendar;
    }
    

    1 回复  |  直到 16 年前
        1
  •  0
  •   Rowland Shaw    16 年前

    尝试使用 BindingList<Calendar> 而不仅仅是一个 List<Calendar>

    您看到的是,当您调整大小时,控件正在重新绘制,并且它将再次遍历所有数据。

    INotifyPropertyChanged 在你的 Calendar 这样,如果绑定列表中的某个项发生更改,就会通知绑定列表