【发布时间】:2012-12-06 21:33:34
【问题描述】:
可能重复:
How to make ListBox editable when bound to a List<string>?
我正在尝试在名为“ListStr”的 List 对象和 ListBox WPF 控件之间设置两个绑定。 此外,我希望这些项目是可编辑的,所以我添加了一个带有 TextBoxes 的 DataTemplate,希望它可以通过 TextBoxes 直接修改 ListStr 项目。
但是当我尝试编辑其中一个时,它不起作用...
有什么想法吗?
PS:我已尝试添加 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 x:Key="dtplItemTextContentListBoxEdit">
<TextBox Text="{Binding Path=.}" Width="175" />
</DataTemplate>
【问题讨论】:
标签: wpf xaml binding listbox datatemplate