如何将Width继承到children元素

时间:2013-11-26 13:02:09

标签: wpf button panel

我有12个按钮,例如一个DockPanel。我的问题是如何将我的DockPanel的宽度继承到按钮,以便它们都具有相同的宽度

        <DockPanel Width="1200" Height="30">
            <Button Width="100" Content="Januar"    />
            <Button Width="100" Content="Februar"   />
            <Button Width="100" Content="März"      />
            <Button Width="100" Content="April"     />
            <Button Width="100" Content="Mai"       />
            <Button Width="100" Content="Juni"      />
            <Button Width="100" Content="Juli"      />
            <Button Width="100" Content="August"    />
            <Button Width="100" Content="September" />
            <Button Width="100" Content="Oktober"   />
            <Button Width="100" Content="November"  />
            <Button Width="100" Content="Dezember"  />
        </DockPanel>

当我改变我的Dockpanel的宽度时,我也想改变按钮的宽度..

我知道..

  

宽度= {Binding ElementName = dockpanel1,Path = Width}

..但我必须采取这个宽度/ 12。

1 个答案:

答案 0 :(得分:2)

使用UniformGrid代替DockPanel

<UniformGrid Rows="1" Width="1200" Height="30">
    <Button Content="Januar"    />
    <Button Content="Februar"   />
    <Button Content="März"      />
    <Button Content="April"     />
    <Button Content="Mai"       />
    <Button Content="Juni"      />
    <Button Content="Juli"      />
    <Button Content="August"    />
    <Button Content="September" />
    <Button Content="Oktober"   />
    <Button Content="November"  />
    <Button Content="Dezember"  />
</UniformGrid>