0

我得到了这个清单:

  List<BoardNote> offlinelist = new List<BoardNote>();

它绑定到我的列表框“boardlist”。现在我希望每次添加新的 Boardnote 后 Listbox 的 UI 都会更新。我已经知道我应该使用“INotifyCollectionChanged”,但我已经过度紧张了。这是“boardlist”的代码:

 <ListBox x:Name="BoardList" ItemsSource="{Binding offlinelist}" > //I need to add binding mode two way and property changed idk
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
                            <TextBox IsReadOnly="True" ScrollViewer.VerticalScrollBarVisibility="Visible" Text="{Binding text}" TextWrapping="Wrap" Foreground="DarkBlue"></TextBox>
                            <AppBarButton Visibility="{Binding visibility}" Icon="Globe" Click="OpenInBrowser" x:Name="Link"></AppBarButton>
                            <AppBarButton Icon="Copy" Click="Copy"></AppBarButton>
                            <AppBarButton Icon="Delete" Click="Delete"></AppBarButton>
                        </StackPanel>
                    </Grid>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
4

2 回答 2

0

您可以使用 ObservalbleList 代替 List。它已经为您实现了 INotifyCollectionChanged。

于 2015-08-21T11:05:31.097 回答
0

您需要在 ViewModel 中实现 ObservableCollection 才能获得更新。

于 2015-08-21T11:09:48.740 回答