【问题标题】:Give equal width to controls inside a Stack Panel为堆栈面板内的控件提供相等的宽度
【发布时间】:2013-06-03 15:01:28
【问题描述】:

我需要在水平的StackPanel 内有两个RadCharts,并希望两个图表的宽度相等。我不想给图表的宽度提供明确的长度。这可以通过使用Grid 控件轻松实现,但我的场景需要StackPanel

【问题讨论】:

    标签: wpf silverlight windows-8 stackpanel


    【解决方案1】:

    文档通常无法快速理解,因为它要么以令人困惑的方式编写,要么所需的信息隐藏在大量其他信息中,这些信息在特定情况下无济于事。因此,在我看来,即使它是“基本的东西”,给出一个快速的答案也没有什么坏处(或者如果一个人认为它太原始,他/她应该什么都不发)。

            <StackPanel Orientation="Horizontal" Grid.IsSharedSizeScope="True">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition SharedSizeGroup="MySizeGroup" />
                    </Grid.ColumnDefinitions>
                    <Button Height="23" Content="Reset" Padding="5,1" />
                </Grid>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition SharedSizeGroup="MySizeGroup" />
                    </Grid.ColumnDefinitions>
                    <Button Height="23" Content="Set" Padding="5,1" />
                </Grid>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition SharedSizeGroup="MySizeGroup" />
                    </Grid.ColumnDefinitions>
                    <Button Height="23" Content="Import" Padding="5,1" />
                </Grid>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition SharedSizeGroup="MySizeGroup" />
                    </Grid.ColumnDefinitions>
                    <Button Height="23" Content="Export" Padding="5,1" />
                </Grid>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition SharedSizeGroup="MySizeGroup" />
                    </Grid.ColumnDefinitions>
                    <Button Height="23" Content="Create new" Padding="5,1" />
                </Grid>
            </StackPanel>
    

    希望这会有所帮助:)

    【讨论】:

    • 我完全同意,是的,这一切都在文档中,是的,但是找到它就像大海捞针
    【解决方案2】:

    将它们放入单独的Grids,使用具有公共SharedSizeGroup 的列,并在StackPanel 上将Grid.IsSharedSizeScope 设置为true

    【讨论】:

    • 1+ 的解决方案,虽然一些示例标记会是完美的。
    • @HighCore:冗余,文档中已经足够了。
    • @sebesbal:很多关于 WPF 的基本内容都是如此,它的文档非常好。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-11
    • 1970-01-01
    • 2015-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多