Grid.IsSharedScopeSize与WPF Grid中的*列不兼容 [英] Grid.IsSharedScopeSize incompatible with * columns in WPF Grid

查看:566
本文介绍了Grid.IsSharedScopeSize与WPF Grid中的*列不兼容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 IsSharedSizeScope 在WPF的ItemsControl中保持每行的宽度相同。



不幸的是,这与 Width ='*'列不兼容,这使'AB C'文本列溢出页面末尾。

 < Border BorderBrush =RedBorderThickness =1> 
< StackPanel Grid.IsSharedSizeScope =True>

< Grid Horizo​​ntalAlignment =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>

这不会包装,但如果您更改 Grid.IsSharedScopeSize false 然后它可以工作,但行不均匀。

有什么聪明的或者我将不得不手动设置'AB C'文本列的宽度?



(注意:这实际上在ItemsControl中未显示)

解决方案

我刚才意识到我不需要为 SharedSizeGroup 设置每一列。通过不为*列设置,我可以实现我需要的包装,同时为其他列保持一致的列宽。



不幸的是,我不认为这适用于*不是网格中最后一列的列,但我还没有尝试过。


I am using IsSharedSizeScope in an ItemsControl in WPF to keep the same widths for each row.

Unfortunately this isn't compatible with 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>

This won't wrap, but if you change Grid.IsSharedScopeSize to false then it does work, but the rows are uneven.

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 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.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆