简体   繁体   English

当控件更改宽度时,如何使DataGrid列拉伸?

[英]How can I make DataGrid columns stretch as the control changes width?

Right now when i re-size my screen the data grid columns are getting cut. 现在,当我调整屏幕大小时,数据网格列将被剪切。 So please give me a solution to re-size my data grid columns when i re-size my window. 因此,当我调整窗口大小时,请给我一个解决方法来调整数据网格列的大小。 How can i set a dynamic width to my data grid columns. 如何为数据网格列设置动态宽度。

<DataGrid Name="dtGrid" > 
  <DataGrid.Columns > 
     <DataGridTextColumn Header="Name" Binding="{Binding custname}" Width="150" /> 
     <DataGridTextColumn Header="Mobile NO" Binding="{Binding Mobileno}" Width="150" FontFamily="Times New Roman"/> 
     <DataGridTextColumn Header="Credit" Binding="{Binding credit}" Width="150" FontFamily="Times New Roman"/> 
     </DataGrid.Columns> 
 </DataGrid>

Instead of giving a hardcode Width to all your columns. 而不是为所有列提供硬编码宽度。 You can mention STAR sizing for your columns, so that the columns will auto adjust based on the available size. 您可以为列提到STAR大小,以便列将根据可用大小自动调整。

   <DataGrid Name="dtGrid">
        <DataGrid.Columns>
            <DataGridTextColumn Header="Name"
                                Binding="{Binding custname}"
                                Width="*" />
            <DataGridTextColumn Header="Mobile NO"
                                Binding="{Binding Mobileno}"
                                Width="*"
                                FontFamily="Times New Roman" />
            <DataGridTextColumn Header="Credit"
                                Binding="{Binding credit}"
                                Width="*"
                                FontFamily="Times New Roman" />
        </DataGrid.Columns>
    </DataGrid>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使 DataGrid 列水平对齐拉伸和自定义列名称 - UWP DataGrid - How to make DataGrid columns horizontalalignment stretch & customize column name - UWP DataGrid 当 Horizo​​ntalAlignment 和 Horizo​​ntalContentAlignment 不起作用时,如何使 WPF 中的控件拉伸以填充可用宽度? - How can I make controls in WPF stretch to fill available width when HorizontalAlignment and HorizontalContentAlignment don't work? 如何使用宽度可调的固定列自定义Datagrid控件? - How to have a Custom Datagrid control with fixed columns whose width is adjustable? 用户控件宽度伸展时,WPF DataGrid缩小列 - WPF datagrid shrinking columns when usercontrol width is stretch 在C#中,如何在Excel中创建DataGrid AutoFit列宽度中的列? - In C# how do you make the columns in a DataGrid AutoFit Column Width like you can in Excel? 如何制作WPF Expander Stretch? - How can I make a WPF Expander Stretch? 如何用字符串填充DataGrid控件? - How can I populate DataGrid control with strings? 如何使LVI延伸到其容器的宽度? - How to make LVI stretch to width of its container? 如何在ListBox内拉伸网格列? - How can I stretch grid columns inside a ListBox? 如何对 DataGrid.RowDetailsTemplate 中的 DataGrid 列进行排序? - How Can I Sort DataGrid Columns that is Inside DataGrid.RowDetailsTemplate?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM