【问题标题】:How to insert a non standard row in a bound datagrid - WPF如何在绑定的数据网格中插入非标准行 - WPF
【发布时间】:2015-05-27 07:45:42
【问题描述】:

我有一个 wpf 数据网格,它绑定到一组数据,其中包含在 xaml 中声明的列和绑定。

我想做的是第一行允许用户对列的其余部分进行大规模更改。

因此,例如,用户可以在顶部组合框中选择一个值,单击该按钮,它会调用一个事件处理程序,该处理程序将更改基础数据并有机会反映在列中的所有组合框中。

如果无法添加自定义行,我想我可以在列标题和行之间创建一个空间,并将“第一行”放置在创建的空间中。

请让我知道这是否可行或您是否需要更多信息。

【问题讨论】:

    标签: c# wpf xaml datagrid


    【解决方案1】:

    您可以覆盖网格内容模板,并拥有一个堆栈面板,其中一个网格用于您的自定义行,另一个网格用于所有其他行,然后可以调整它们的外观以使它们看起来像您想要的那样。..

    这是上述解决方案的一个非常基本的代码----

    <Grid>
        <ScrollViewer>
            <StackPanel Orientation="Vertical">
                <DataGrid ItemsSource="{Binding list1}">
                    <DataGrid.Columns>
                        <DataGridTemplateColumn Header="ComboCol" Width="50">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <ComboBox Text="Bind Your Combo Box" IsEditable="True"></ComboBox>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>
                    </DataGrid.Columns>
                </DataGrid>
                <DataGrid ItemsSource="{Binding list2}" HeadersVisibility="Row">
                    <DataGrid.Columns>
                        <DataGridTextColumn Header="Line1" Binding="{Binding Path=.}" Width="50"/>
                        <DataGridTextColumn Header="Line2" Binding="{Binding Path=.}" Width="50"/>
                    </DataGrid.Columns>
                </DataGrid>
                <DataGrid/>
            </StackPanel>
        </ScrollViewer>
    </Grid>
    

    【讨论】:

    • 听起来很有希望,您能否提供更多信息?
    • 添加了一些代码给你一个想法,你可以设置网格绑定来让你的方式..
    • 好吧,我明白你的意思了。我会试一试。如果我有 2 个单独的数据网格,则可以看到滚动的潜在并发症。
    • 在其中添加了滚动位,这将使您的网格滚动为一体,此外,您会发现一些有关滚动事件聚合的问题,但我确信对 SO 进行简单搜索将解决这些问题.. 祝你好运!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-05-28
    • 2011-08-14
    • 2011-09-28
    • 2010-11-15
    • 1970-01-01
    相关资源
    最近更新 更多