【发布时间】:2014-02-11 07:54:22
【问题描述】:
我有代表我的程序中用户可以访问的模块的复选框。
您可以从 DataGrid 中看到,第四列中的模块是从“DataContext.ModuleCollection”创建的,而 DataGrid 的行是从 UserCollection 创建的。我希望 User_ID 成为每个复选框的内容。这将设置为我在底部尝试过的复选框样式,但没有取得多大成功。
我的问题是,复选框位于模块级别(在数据中),我需要想办法回到用户级别以获取 User_ID。
User_ID 是行数据集的一部分,例如用户记录。
我如何获得下面样式的 User_ID 是个问题?
下面是我的数据网格:
<DataGrid ItemsSource="{Binding UserCollection}" >
<DataGrid.Columns>
<DataGridTextColumn Header="Name" Binding="{Binding Path=Name}"/>
<DataGridTextColumn Header="Job Title" Binding="{Binding Path=Job_Title}"/>
<DataGridTextColumn Header="Company" Binding="{Binding Path=Company}"/>
<DataGridTemplateColumn CanUserReorder="True">
<DataGridTemplateColumn.Header>
<ItemsControl ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.ModuleCollection}" >
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" Background="Transparent" CanVerticallyScroll="False" CanHorizontallyScroll="False"></StackPanel>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Style="{StaticResource ListViewItemRotatedText}" Text="{Binding ModuleName}" >
</TextBlock>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</DataGridTemplateColumn.Header>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ItemsControl ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.ModuleCollection}" >
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" Background="Transparent" CanVerticallyScroll="False" CanHorizontallyScroll="False"></StackPanel>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<CheckBox Style="{StaticResource ListViewItemCheckbox}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
以下是我的检查方式:
<Style x:Key="ListViewItemCheckbox" TargetType="CheckBox">
<Setter Property="Content" Value="{Binding Path=User_ID, RelativeSource={RelativeSource AncestorType={x:Type DataGridRow}}}"/>
</Style>
【问题讨论】:
-
我希望 User_ID 成为每个复选框的内容。您希望每一行中的相同
User_ID值出现在 all 中那一行有五个Checkboxes? -
是的,它可能看起来很奇怪,但我只是想弄清楚如何获得它的参考。我最终会将其发送到与复选框相同级别的转换器。
-
这是我第四次改写这个问题,非常感谢您的帮助!
-
我知道...它一直难以理解...现在回答。给我5个
标签: wpf xaml wpfdatagrid