Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 将字符串的ObservableCollection绑定到模板化的ListBox_Wpf_Templates_Data Binding_Listbox_Observablecollection - Fatal编程技术网

Wpf 将字符串的ObservableCollection绑定到模板化的ListBox

Wpf 将字符串的ObservableCollection绑定到模板化的ListBox,wpf,templates,data-binding,listbox,observablecollection,Wpf,Templates,Data Binding,Listbox,Observablecollection,我有这个收藏 ObservableCollection<string> Urls { get; set; } 在我的数据上下文类中。我的列表框中有一个绑定: <ListBox ItemsSource="{Binding Urls}"> <ListBox.ItemTemplate> <DataTemplate> <TextBox Text="{Binding .}" />

我有这个收藏

ObservableCollection<string> Urls { get; set; }
在我的数据上下文类中。我的列表框中有一个绑定:

<ListBox ItemsSource="{Binding Urls}">

    <ListBox.ItemTemplate>
        <DataTemplate>
            <TextBox Text="{Binding .}" />
        </DataTemplate>
    </ListBox.ItemTemplate>

</ListBox>
数据显示在列表框中,两个相应的按钮(此处未显示)以及添加和删除工作命令,但是,更改文本框不会影响集合的内容

我在绑定中尝试了Mode=TwoWay,但我认为它已经打开了。我尝试了一些其他选项,比如Validate=OnPropertyChange,但是仍然没有得到更新


如何使ListBox中模板化项所在的文本框实际更新datacontext类的URL属性?

您不能修改字符串;使用具有一个字符串属性的包装器类,然后将文本框绑定到所述属性。这样,属性中的字符串可以替换为已编辑的字符串。

您不能修改字符串;使用具有一个字符串属性的包装器类,然后将文本框绑定到所述属性。这样,属性中的字符串可以替换为已编辑的字符串