我在 Google 上进行了广泛搜索,并且正在努力寻找一个简单的示例来遵循 ItemsControl,我认为我需要能够执行以下操作。
我目前有一个带有可滚动列表框的网格,其中包含复选框,使用以下 XAML 布局按预期工作
<Grid>
<ListBox ScrollViewer.VerticalScrollBarVisibility="Auto"
ItemsSource="{Binding Selections}" Margin="12,22,12,94">
<ListBox.ItemTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding IsChecked}"
Content="{Binding Path=Item.SelectionName}">
</CheckBox>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
我现在想在每个 Checkbox 的右侧添加一个 TextBox,使其与每行 1 个 Checkbox 和 1 个 Textbox 水平对齐。我以为我必须使用 ItemsControl 来允许两个控件但使用 ItemsControl 如下我失去了滚动的能力
<Grid>
<ItemsControl ScrollViewer.VerticalScrollBarVisibility="Auto"
ItemsSource="{Binding Selections}" Margin="12,22,12,94">
<ItemsControl.ItemTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding IsChecked}"
Content="{Binding Path=Item.SelectionName}">
</CheckBox>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
另外,如果我尝试添加一个类似于
<DataTemplate>
<CheckBox IsChecked="{Binding sChecked}" Content="{Binding Path=Item.BookieName}" />
<TextBox />
</DataTemplate>
我收到一个错误The object 'DataTemplate' already has a child and cannot add 'TextBox'
本质上,我希望它看起来像这样
谁能给我一些关于如何在 XAML 中构造控件以获得我想要的布局的指示?