首页 > 解决方案 > 在另一个列表视图的项目中单击事件后加载列表视图的数据

问题描述

我想在另一个列表视图的项目中单击事件后加载列表视图的数据例如,我有列表视图 A:ABC 并且在 A 中单击后将有 DEF,在 B 中单击将具有 GHI,C 将具有 JKL

问题是我必须从 Startup 事件加载它,所以它不会有 Null Reference Exception 事件。然后我加载了它,但它没有显示我想要的结果(仅来自启动事件的数据)。此外,我调试代码并弄清楚它有数据但启动时的数据不让它们显示。注意:另一个 ListView 显示在 Popup 上那么,我该如何解决这个问题?

标签: c#wpflistview

解决方案


public ObservableCollection<int> Chars { get; set; }

private async void ClickItem(object sender, RoutedEventArgs e)
{
      await Dispatcher.BeginInvoke((Action)delegate () 
      {
           for (int i = 1; i <= 3; i++)
           {
                Chars.Add(Chars.Count + 1);
           }                
       }, DispatcherPriority.Input);
}

xml

   <ListView ItemsSource="{Binding Chars}">
        <ListView.ItemTemplate>
            <DataTemplate>
                <Button Content="{Binding }" Click="ClickItem"></Button>
            </DataTemplate>
        </ListView.ItemTemplate>
   </ListView>

推荐阅读