可能是重复问题:
如何在绑定到List<string>时使ListBox可编辑?
我正在尝试在一个名为“ListStr”的列表对象和一个ListBox WPF控件之间设置双向绑定。 此外,我希望这些项是可编辑的,所以我添加了一个DataTemplate和TextBoxes,期望通过TextBoxes直接修改ListStr项。
但是当我尝试编辑其中一个时,它不起作用......
有什么想法吗?
附注:我已经尝试添加Mode=TwoWay参数,但仍然不起作用。
这是XAML代码:
<ListBox ItemsSource="{Binding Path=ListStr}" Style="{DynamicResource ResourceKey=stlItemTextContentListBoxEdit}" />
这里是样式代码:
<Style x:Key="stlItemTextContentListBoxEdit" TargetType="{x:Type ListBox}">
<Setter Property="Background" Value="#FF0F2592" />
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="Foreground" Value="White" />
<Setter Property="Height" Value="150" />
<Setter Property="Width" Value="200" />
<Setter Property="HorizontalContentAlignment" Value="Left" />
<Setter Property="ItemTemplate" Value="{DynamicResource ResourceKey=dtplItemTextContentListBoxEdit}" /></Style>
而且DataTemplate:
<DataTemplate x:Key="dtplItemTextContentListBoxEdit">
<TextBox Text="{Binding Path=.}" Width="175" />
</DataTemplate>