我需要在带有复选框的列表框中加载一些数据(员工)。所以问题是我如何加载其他值,因为此时我只能加载员工的“姓名”,我需要加载其他数据,如“姓氏”、“年龄”...等
我不知道内容中的语法应该如何。
这是xaml
<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox Name="CheckBoxZone" Content="{Binding Name}" Tag="{Binding TheValue}" Checked="CheckBoxZone_Checked"
Margin="0,5,0,0"/>
</DataTemplate>
</ListBox.ItemTemplate>
最佳答案
基本上,您必须增强 ListItem 模板的布局,以便与 CheckBox 一起显示另一个控件:
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<CheckBox Grid.Column="0" Name="CheckBoxZone" Content="{Binding Name}" Tag="{Binding TheValue}" Checked="CheckBoxZone_Checked" Margin="0,5,0,0"/>
<TextBlock Grid.Column="1" Text="{Binding LastName}"></TextBlock>
</Grid>
</DataTemplate>
如果你想将 item 本身传递给 CheckBox 的内容(为什么你需要那个?)只需使用这个:
<CheckBox Grid.Column="0" Name="CheckBoxZone" Content="{Binding}" Tag="{Binding TheValue}" Checked="CheckBoxZone_Checked" Margin="0,5,0,0"/>
关于c# - 使用复选框在 ListBox 中加载数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7028044/