XAML 布局StackPanel

时间:2023-03-09 19:13:12
XAML 布局StackPanel

版权声明:本文为博主原创文章。未经博主同意不得转载。 https://blog.****.net/Fanbin168/article/details/24768459

<Window x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid Height="320" Width="513">
<!--Orientation="Horizontal"表示垂直的布局。=Vertical要则是水平布局,假设省略Orientation默认就是水平布局-->
<!--StackPanel就是页面布局,假设不加的话。你把一个控件直接放入Grid里面的话,那这个控件就会填充满整个窗口-->
<!--<StackPanel Orientation="Horizontal">
<Button Content="登陆" Name="bntLogin" Click="bntLogin_Click"></Button>
<Button Content="提交" Name="bntSubmit"></Button>
</StackPanel>--> <!--直接在Grid里放控件。那么这个控件就会把整个窗口都填充满,利用这一点,我们能够在这个控件里面放一个控件,事实上我说的就是在一个button里放入一个image图片控件。事实上也就是将button的Content属性设定为一副图片,那么这个控件就会显示为一副图片的样子了,哈哈哈-->
<!--<Button Margin="0,0,13,0">
<Button.Content>
<Image Source="123.jpg" Height="259" Width="494"></Image>
</Button.Content>--> <!--</Button>--> <!--假如说我的这个button想放入两个控制,或者很多其它的控件怎么办呢?-->
<Button >
<Button.Content>
<StackPanel>
<Image Source="123.jpg"></Image>
<!--VerticalAlignment="Center"表示垂直的对齐方式,, HorizontalContentAlignment="Center"表示水平的对齐方式-->
<TextBox Text="美女哦!" HorizontalContentAlignment="Center" VerticalAlignment="Center"></TextBox>
</StackPanel>
</Button.Content> </Button> </Grid>
</Window>