Mic*_*ing 3 c# xaml binding listbox
这可能是一个非常简单的问题,但目前我实际上不知道该谷歌什么。
如果我有一个这样的对象:
public class Employee
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
在我的 VM 中,我有一个员工列表 ( 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>
Run Code Online (Sandbox Code Playgroud)
但是如果我的员工列表包含字符串而不是Employee对象呢?如何将这些字符串值绑定到TextBlock数据模板中?
| 归档时间: |
|
| 查看次数: |
2967 次 |
| 最近记录: |