有关在wpf中拉伸组框的问题

问题描述 投票:1回答:1

我的设计如下。

<Dock:ContentPane x:Name="grouping" Header="{lex:LocText Res:Titles:CustomFields}"  
                    Visibility="{Binding ShowGroups, Converter={StaticResource VisibilityCollapseIfFalse}, Source={x:Static Management:UserPreferencesManager.Instance}}" >
    <ScrollViewer Style="{DynamicResource VerticalScrollViewerStyle}" >
        <DockPanel Style="{DynamicResource DefaultPanelStyle}" >
            <SKUL:CustomFields />
            <SKUL:CustomFieldsPortrait Windows:OrientationMonitor.HorizontalVisibility="Collapsed" />
        </DockPanel>
    </ScrollViewer>
</Dock:ContentPane>   

我的CustomeFields.xaml

<Expander IsExpanded="{Binding ExpanderSetting}">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>                    
        </Grid.ColumnDefinitions>

        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <GroupBox Style="{DynamicResource DefaultGroupBoxStyle}" Header="{lex:LocText Res:Titles:ItembyLocationGroups}" >
            <Common:CustomFields DataContext="{Binding Grouping.SKULGroups}" IsReadOnly="True" />
        </GroupBox>
    </Grid>
</Expander>  

当我拉伸我的堆栈窗格时,我的组合框没有得到拉伸。我怎么能实现它。我尝试使用Horizo​​ntalAligment =“strech”verticalAligment =“strech”属性,但它没有工作

wpf xaml stackpanel groupbox
1个回答
1
投票

这是开发人员使用StackPanel时常见的问题。这个Panel不像WPF中的其他Panels那样执行调整大小的动作。要纠正这个问题,只需用StackPanel或其他Grid替换Panel,它可以为孩子们提供调整大小的能力。

您可以从MSDN上的Panel页面找到有关不同Panels Overviews及其不同大小调整策略的更多信息。


更新>>>

在给定145的My RowDefinition Height中,是否会导致问题?

我想是这样的......你在Height或其任何一个主控件上设置的任何Widths或GroupBoxs将阻止它伸展到应用程序的完整HeightWidth。看一下这个展示StackPanelGrid之间差异的例子:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition />
    </Grid.RowDefinitions>
    <StackPanel Grid.Row="0" Background="Red">
        <GroupBox Background="LightGreen">
            <GroupBox.Header>Some Header</GroupBox.Header>
            <TextBlock Text="Some Content" FontSize="50" HorizontalAlignment="Center"/>
        </GroupBox>
    </StackPanel>
    <GroupBox Grid.Row="1" Background="LightGreen">
        <GroupBox.Header>Some Header</GroupBox.Header>
        <TextBlock Text="Some Content" FontSize="50" HorizontalAlignment="Center" />
    </GroupBox>
</Grid>
© www.soinside.com 2019 - 2024. All rights reserved.