Grid.IsSharedScopeSize与WPF Grid中的*列不兼容 [英] Grid.IsSharedScopeSize incompatible with * columns in WPF Grid
问题描述
我正在使用 IsSharedSizeScope
在WPF的ItemsControl中保持每行的宽度相同。
不幸的是,这与 Width ='*'
列不兼容,这使'AB C'文本列溢出页面末尾。
< Border BorderBrush =RedBorderThickness =1>
< StackPanel Grid.IsSharedSizeScope =True>
< Grid HorizontalAlignment =Stretch>
< Grid.ColumnDefinitions>
< ColumnDefinition Width =AutoSharedSizeGroup =G1/>
< ColumnDefinition Width =AutoSharedSizeGroup =G2/>
< ColumnDefinition Width =*SharedSizeGroup =G3/>
< /Grid.ColumnDefinitions>
< TextBlock Text =Col0Grid.Column =0Margin =0,0,5,0/>
< TextBlock Text =Col1Grid.Column =1Margin =0,0,5,0/>
< / Grid>
< / StackPanel>
< / Border>
这不会包装,但如果您更改 有什么聪明的或者我将不得不手动设置'AB C'文本列的宽度? (注意:这实际上在ItemsControl中未显示) 我刚才意识到我不需要为 不幸的是,我不认为这适用于*不是网格中最后一列的列,但我还没有尝试过。 I am using Unfortunately this isn't compatible with This won't wrap, but if you change Is there any clever way to achieve this, or will I have to manually set a width on the 'A B C' text column? (Note: This is actually inside an ItemsControl not shown) I just realized I don't need to set Unfortunately I don't think this will work for * columns that aren't the last column in the grid but I haven't tried yet. 这篇关于Grid.IsSharedScopeSize与WPF Grid中的*列不兼容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! Grid.IsSharedScopeSize
到
false
然后它可以工作,但行不均匀。
SharedSizeGroup
设置每一列。通过不为*列设置,我可以实现我需要的包装,同时为其他列保持一致的列宽。
IsSharedSizeScope
in an ItemsControl in WPF to keep the same widths for each row.Width='*'
columns, which makes the 'A B C' text column spill off the end of the page.<Border BorderBrush="Red" BorderThickness="1">
<StackPanel Grid.IsSharedSizeScope="True">
<Grid HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" SharedSizeGroup="G1"/>
<ColumnDefinition Width="Auto" SharedSizeGroup="G2" />
<ColumnDefinition Width="*" SharedSizeGroup="G3" />
</Grid.ColumnDefinitions>
<TextBlock Text="Col0" Grid.Column="0" Margin="0,0,5,0"/>
<TextBlock Text="Col1" Grid.Column="1" Margin="0,0,5,0"/>
<TextBlock Text="A B C D E F G H I J K L M N O P Q R S T U V W X Y Z" TextWrapping="Wrap" Grid.Column="2"/>
</Grid>
</StackPanel>
</Border>
Grid.IsSharedScopeSize
to false
then it does work, but the rows are uneven.SharedSizeGroup
for every column. By not setting it for the * column I can achieve the wrapping I need while maintaining consistent column widths for the other columns.