WPF组合框绑定/ ObservableCollection对象

时间:2018-03-25 16:42:07

标签: c# wpf combobox binding observablecollection

组合框绑定有问题;

我有一个看起来像这样的Observable Collection;

enter image description here

这是我的组合框的样子:

<ComboBox ItemsSource="{Binding settingsViewModel.sFTPs}"
      DisplayMemberPath="Folder"
      SelectedValuePath="Folder"
      SelectedValue="{Binding settingsViewModel.sFTPs[0].Folder}"
      Grid.Column="0" Grid.Row="4"
      md:HintAssist.IsFloating="True"
      md:HintAssist.Hint="Save Directory"
      md:HintAssist.FloatingScale="1.5"
      Margin="5"
      />

它会返回项目列表,但是当我尝试保存它时会这样做;

[SFTP Connection]
Host=
Port=
UserName=
Password=
Type=SFTP
SavePath=Folder1

这是我的保存方法:

private void ExecuteSaveCommand(object param)
{

    IniFile iniFile = new IniFile();

    iniFile.Load(@"Configuration.ini");

    foreach (var itemCollection in sFTPs)
    {
        iniFile.Sections[0].Keys[0].Value = itemCollection.Address;
        iniFile.Sections[0].Keys[1].Value = itemCollection.Port;
        iniFile.Sections[0].Keys[2].Value = itemCollection.UserName;
        iniFile.Sections[0].Keys[3].Value = itemCollection.Password;
        iniFile.Sections[0].Keys[4].Value = "SFTP";
        iniFile.Sections[0].Keys[5].Value = itemCollection.Folder;
    }
    iniFile.Save(@"Configuration.ini");
}

1 个答案:

答案 0 :(得分:0)

创建节的代码不是追加新元素,而是使用当前元素反复覆盖相同的节。这导致只保存最后一个元素。

could not deduce template argument for "Interval"