【问题标题】:how to place datagrid column at the end of the datagrid row in wpf?如何将datagrid列放在wpf中datagrid行的末尾?
【发布时间】:2018-04-24 13:35:43
【问题描述】:

我在一个网格中有一个数据网格,其中有两个列,一个是文本,另一个是按钮,下面是我的 wpf 代码

<Grid Grid.Column="2"
          Grid.Row="1">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
          </Grid.RowDefinitions>
            <DataGrid.Columns>
                <DataGridTextColumn Binding="{Binding Path=GroupName}"
                                    Header="Group Name" />
                <DataGridTemplateColumn Header="Actions"
                                        Width="2"   
                                        ToolTipService.ToolTip="Remove Group"                                            
                                        IsReadOnly="True">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Button 
                                    Style="{StaticResource CustXButton}"
                                    Command="Delete" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
            </DataGrid.Columns>
        </DataGrid>
    </Grid>

如何将第二个数据网格列,即“x”按钮放置在该行中数据网格的末尾?我尝试为按钮设置边距,但没有用。非常感谢任何帮助。谢谢

【问题讨论】:

    标签: c# wpf xaml datagrid datagridtemplatecolumn


    【解决方案1】:

    只需将Width="*" 添加到您的组名列,即可使用所有可用空间。

        <Grid Grid.Column="2"
          Grid.Row="1">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <DataGrid>
            <DataGrid.Columns>
                <DataGridTextColumn Binding="{Binding Path=GroupName}"
                                    Header="Group Name" 
                                    Width="*"/>
                <DataGridTemplateColumn Header="Actions"
                                        Width="2"   
                                        ToolTipService.ToolTip="Remove Group"                                            
                                        IsReadOnly="True">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Button 
                                    Style="{StaticResource CustXButton}"
                                    Command="Delete" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
            </DataGrid.Columns>
        </DataGrid>
    </Grid>
    

    【讨论】:

    • 感谢@Roger Leblanc
    猜你喜欢
    • 2014-10-18
    • 2010-10-05
    • 2010-11-20
    • 2013-02-03
    • 1970-01-01
    • 1970-01-01
    • 2015-08-03
    • 2011-06-07
    • 1970-01-01
    相关资源
    最近更新 更多