C# 通过DataTemplate实现可编辑的ListBox项目后,不会更新ListBox.ItemsSource

C# 通过DataTemplate实现可编辑的ListBox项目后,不会更新ListBox.ItemsSource,c#,wpf,listbox,C#,Wpf,Listbox,我实现了可编辑的ListBox项,就像在这个答案中发布的一样 但是新值不会在我的列表框的ItemsSource对象中更新 这是XAML: <ListBox Grid.Row="2" Name="ds_ConfigProfiles" ItemsSource="{Binding ConfigProfiles}" SelectedItem="{Binding ActiveConfigProfile}" IsSynchronizedWithCurrentItem="True" Panel.ZInd

我实现了可编辑的
ListBox
项,就像在这个答案中发布的一样

但是新值不会在我的列表框的
ItemsSource
对象中更新

这是XAML:

<ListBox Grid.Row="2" Name="ds_ConfigProfiles" ItemsSource="{Binding ConfigProfiles}" SelectedItem="{Binding ActiveConfigProfile}" IsSynchronizedWithCurrentItem="True" Panel.ZIndex="-1">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <!-- TODO: this is meant for allowing edit of the profile names, but the new name does not get stored back to ConfigProfiles -->
            <local:TextToggleEdit Text="{Binding Path=., Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" MinWidth="40" Height="23" />
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>
我理解错了什么吗

可能是因为项目源的类型为
observedcollection
,而不是
observedcollection
(这是遗留原因)

我对WPF比较陌生,对如何调试这个问题没有想法

可能是因为项目源的类型为
observedcollection
,而不是
observedcollection
(这是遗留原因)

是的,没错。不能修改
字符串,因为它是不可变的。您需要绑定到类的
字符串
属性,这意味着您需要用
可观察集合
替换
可观察集合


我担心绑定引擎不会用新的
string
替换
ObservableCollection
中的
string
,如果这正是您所希望的。

Path=。
当您将代码粘贴到其中时,您更改了什么,或者您在绑定路径中确实有时间段吗?“如何调试此”-检查输出窗口中的绑定错误,设置断点并检查是否所有操作都按预期运行。我不确定这应该是如何工作的(用过的答案作者没有费心解释),也许你发布一个完整的并解释它,然后其他人可以为你调试它。@James看看这里,我也必须学习这个符号:@Sinatr感谢你提出我已经做了几个小时的建议(当然,你不可能知道这一点:) ). 但我绝对不需要s。o。除此之外,我还需要为自己调试代码——我总是尽可能准确地理解事情(尽管我知道自己的能力有限)。
/// <summary>Configuration profiles that were found in the active storage path</summary>
public ObservableCollection<string> ConfigProfiles { get; private set; } = new ObservableCollection<string>();