对不起,这是一个非常简单的问题。但是目前我实际上并不知道要谷歌什么。如何将IEnumerable <string>绑定到ListBox?
如果我有这样的对象:
public class Employee
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
在我的虚拟机我公司员工的(public List<Employee> Employees
)的列表。这很容易在我的XAML中绑定这个到ListBox:
<ListBox ItemsSource={Binding Employees}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding FirstName}"/>
<TextBlock Text="{Binding LastName}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
但是,如果我的员工的列表将包含字符串,而不是Employee
对象?我怎样才能将这些字符串值绑定到数据模板中的TextBlock
?
你必须设置绑定模式,在这种情况下'mode =“two-way”' – David 2012-03-09 07:47:04
为什么我需要设置文本块的双向绑定?单向绑定的作用是“Property => UI-Element方式”。另一种方式需要双向绑定(UI-E => Prop)。并且您不能更改文本块中的数据。 – 2012-03-09 10:12:20