對不起,這是一個非常簡單的問題。但是目前我實際上並不知道要谷歌什麼。如何將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