我正在嘗試將數(shù)據(jù)網(wǎng)格添加到主控件寬度設(shè)置為拉伸的 UserControl??丶惶砑拥街髅姘迳系?StackPanel 中,我希望控件的寬度可以拉伸。我的數(shù)據(jù)網(wǎng)格設(shè)置了寬度,但除非我在用戶控件上定義寬度,否則所有列都會(huì)縮小到大約 10 像素。<Expander Header="Issues" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" Margin="4,86,4,4" VerticalAlignment="Stretch" IsExpanded="False"> <Grid Background="#FFE5E5E5" HorizontalAlignment="Stretch" Width="Auto"> <DataGrid x:Name="dg_issues" CanUserResizeRows="False" CanUserReorderColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" CanUserSortColumns="False" CanUserResizeColumns="True" HorizontalAlignment="Stretch" AutoGenerateColumns="False" HeadersVisibility="Column" SelectionMode="Single"> <DataGrid.Columns> <DataGridTextColumn Header="ID" Binding="{Binding Key}" Width="60"/> <DataGridTextColumn Header="Status" Binding="{Binding Status}" Width="60"/> <DataGridTextColumn Header="Summary" Binding="{Binding Summary}" Width="*"/> <DataGridTextColumn Header="Time Spent" Binding="{Binding TimeSpent}" Width="70"/> <DataGridTextColumn Header="Remaining" Binding="{Binding Remaining}" Width="70"/> </DataGrid.Columns> </DataGrid> </Grid></Expander>
1 回答

慕蓋茨4494581
TA貢獻(xiàn)1850條經(jīng)驗(yàn) 獲得超11個(gè)贊
原來用水平滾動(dòng)條將數(shù)據(jù)網(wǎng)格包裝在 ScrollViewer 中會(huì)導(dǎo)致此問題。
我發(fā)現(xiàn)這個(gè)問題讓我找到了解決方案,禁用單杠,因?yàn)槲也恍枰?a >DataGrid 周圍的 WPF ScrollViewer 影響列寬
<ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
- 1 回答
- 0 關(guān)注
- 185 瀏覽
添加回答
舉報(bào)
0/150
提交
取消