我需要能够填充stackpanel,buttons但按钮必须首先出现在stackpanel的底部并向上填充.这些按钮是动态创建的,并且它们的数量未知,因此视觉上的hackery将无法正常工作.我尝试过垂直对齐,但无济于事.
Pop*_*lin 46
像这样:
<StackPanel VerticalAlignment="Bottom">
...
</StackPanel>
Run Code Online (Sandbox Code Playgroud)
要向上填充按钮,必须将按钮插入位置0,而不是添加它们.
Nir*_*Nir 16
或者您可以将StackPanel旋转180度以使按钮从底部到顶部堆叠,然后再将按钮旋转180度以使它们再次正面朝上:
<StackPanel>
<!-- rotate all buttons inside this panel -->
<StackPanel.Resources>
<Style TargetType="Button">
<Setter Property="LayoutTransform">
<Setter.Value>
<RotateTransform Angle="180"/>
</Setter.Value>
</Setter>
</Style>
</StackPanel.Resources>
<!-- rotate the stack panel -->
<StackPanel.LayoutTransform>
<RotateTransform Angle="180"/>
</StackPanel.LayoutTransform>
<!-- content -->
<Button>1</Button>
<Button>2</Button>
</StackPanel>
Run Code Online (Sandbox Code Playgroud)
另一种方法是使用DockPanel.
只需在DockPanel上将LastChildFill设置为false即可.
然后在添加到DockPanel之前,将附加的Dock属性设置为要添加到Bottom的每个按钮.
例如:
var button = new Button();
DockPanel.SetDock(button, Dock.Bottom);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
30198 次 |
| 最近记录: |