不能够拉伸的内侧的StackPanel [英] Not able to stretch an inner StackPanel

查看:812
本文介绍了不能够拉伸的内侧的StackPanel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Usingthe设置下面,我可以用颜色窗口紫色的整个宽度。内堆叠面板是chartreusian并向左偏移。

Usingthe setup below, I can color the whole width of the window purplish. The inner stack panel is chartreusian and shifted to the left.

<StackPanel HorizontalAlignment="Stretch"
            Orientation="Horizontal"
            Background="BlueViolet"
            Height="70">
  <StackPanel HorizontalAlignment="Left"
              Orientation="Horizontal"
              Background="Chartreuse" >

我期待,如果我改变了内堆面板streched的水平对齐方式,它会填满了所有的宽度以及但这并没有发生。我都试过权和streched路线,似乎它不影响内部控制的宽度。

I was expecting that if I changed the horizontal alignment of the inner stack panel to streched, it'd fill out all the width as well but that doesn't happen. I've tried both right and streched alignments and it seems that it's not affecting the width of the inner control.

据我发现,的职位是的方式来实现它(和它肯定工作的外部控制)。我能会丢失?我辗转于外板声明的其他控件(即所有的兄弟姐妹到chartreusily彩色的),没有区别。

According to the posts I've found that is the way to achieve it (and it certainly worked for the outer control). What can I be missing? I've removed the other controls declared in the outer panel (i.e. all the siblings to the chartreusily colored one) with no difference.

推荐答案

A 的StackPanel 的要求,但也只是少到需要将提供给它的内容尽可能多的空间。

A StackPanel will provide to its content as much space as required but also only as few as necessary.

如果您想要填满窗口的完全宽度,只需更换外的StackPanel 电网

If you want to fill exactly the width of the window, just replace the outer StackPanel by a Grid

如果你想在的StackPanel 来着,你可以绑定了minWidth 其父填补至少整个 ActualWidth的

If you want the StackPanel to fill at least the whole with, you can bind the MinWidth to its parent ActualWidth:

<StackPanel HorizontalAlignment="Stretch"
    Name="parent"
    Orientation="Horizontal"
    Background="BlueViolet"
    Height="70">

    <StackPanel HorizontalAlignment="Stretch"
        MinWidth="{Binding Path=ActualWidth, ElementName=parent}"
        Orientation="Horizontal"
        Background="Chartreuse" >
    </StackPanel>
</StackPanel>

这篇关于不能够拉伸的内侧的StackPanel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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