-1

再会,

我有一个 WPF MVVM 应用程序,它允许用户将项目拖到列表框中。这第一次成功。但是,如果需要,我需要能够将更多项目拖到列表框中。

        <!-- XAML FileSelectionView.xaml -->
        <ListBox x:Name="listboxFileGroups"
                 ItemsSource="{Binding ImportGroups, Mode=TwoWay}"
                 SelectedItem="{Binding Path=SelectedValue,
                                        Mode=TwoWay}"
                 Style="{StaticResource myListboxStyle}"
                 helper:FocusExtension.IsFocused="{Binding IsImportGroupsFocused}"
                 telerik:RadDragAndDropManager.AllowDrop="True"
                 telerik:RadDragAndDropManager.DropInfo="OnDropInfo"
                 telerik:RadDragAndDropManager.DropQuery="OnDropQuery" />

这是我的视图模型 (FileSelectionViewModel.cs) 以及实现 INotifyPropertyChanged 的​​相关代码:

    // This is the data source of the top listbox
    private ObservableCollection<string> importGroups;
    public ObservableCollection<string> ImportGroups
    {
        get 
        {
            System.Diagnostics.Debug.WriteLine("Retrieving Top Level Import Groups...");
            importGroups = fileImportProcess.ImportGroups;
            return importGroups;
        }

        set
        {
            importGroups = value;
            fileImportProcess.ImportGroups = importGroups;
            System.Diagnostics.Debug.WriteLine("Initializing Top Level Import Groups...");
            OnPropertyChanged("ImportGroups");
        }
    }

FileSelectionViewModel.cs 然后接受这些更改并将它们传播到一个名为 FileImportProcess.cs 的类中(这也实现了 INotifyPropertyChanged),如下所示:

    // This is the data source for FileSelection
    private ObservableCollection<string> importGroups;
    public ObservableCollection<string> ImportGroups
    {
        get 
        {
            System.Diagnostics.Debug.WriteLine("Retrieving Lower Level Import Groups");
            return parsedFiles.Keys.ToList().ToObservableCollection<string>();
        }
        set
        {
            importGroups = value;
            System.Diagnostics.Debug.WriteLine("Initializing Lower Level Import Groups");
            foreach (var item in importGroups)
            {
                System.Diagnostics.Debug.WriteLine("==> " + item.ToString());
            }
            OnPropertyChanged("ImportGroups");
        }
    }

我遇到的问题是我第一次将三个文件拖到列表框中,一切正常。当我尝试将更多文件拖到列表框中时,FileImportProcess.cs 类会确认我选择的额外文件,但不会将事件传播到 FileSelectionViewModel.cs。这是我的示例输出:

Initializing Lower Level Import Groups
==> Import Group 1
==> Import Group 2
==> Import Group 3

Retrieving Top Level Import Groups...
Retrieving Lower Level Import Groups
Retrieving Top Level Import Groups...
Retrieving Lower Level Import Groups
Retrieving Top Level Import Groups...
Retrieving Lower Level Import Groups

0 - C:\Dropbox\Dropbox-Logs\NSN_2013_02_20_eNodeB_Funktion_Load_M8000-10.csv
1 - C:\Dropbox\Dropbox-Logs\NSN_2013_02_20_ENODEB_FUNKTION_LOAD_M8018-22.csv
2 - C:\Dropbox\Dropbox-Logs\NSN_2013_02_20_ENB_Transport_Load_M8004-11.csv
3 - C:\Dropbox\Dropbox-Logs\NSN_2013_02_20_EUTRAN_RELATION_HO_M8015-20.csv
4 - C:\Dropbox\Dropbox-Logs\NSN_2013_02_20_EUTRANCELL_BEARER_M8007-13.csv
5 - C:\Dropbox\Dropbox-Logs\NSN_2013_02_20_EUTRANCELL_ENB_HO_M8009-15.csv
6 - C:\Dropbox\Dropbox-Logs\NSN_2013_02_20_EUTRANCELL_HO_M8021-24.csv

Initializing Lower Level Import Groups
==> Import Group 1
==> Import Group 2
==> Import Group 3
==> Import Group 4
==> Import Group 5
==> Import Group 6
==> Import Group 7

如您所见,当我第一次拖动文件时,ViewModel 会检索 ImportGroups。第二次拖动其他文件时,我收到了输入文件,但列表框没有正确更新。

编辑*** 我在“输出”窗口中看不到任何内容表明数据绑定有任何问题***

有任何想法吗?

TIA,

科森

4

1 回答 1

0

尝试ItemsSource="{Binding ImportGroups, Mode=OneWay,UpdateSourceTrigger=PropertyChanged}"

于 2013-06-27T05:42:13.183 回答