对齐 StackPanel 中的元素

我有一个堆栈面板,其中有一个几何按钮、文本块和两个平面按钮。尽管我已经给每个元素单独的水平对齐,但它们似乎都是从我的左侧堆叠起来的...


我希望我的几何按钮和文本块与堆栈面板的左侧对齐,而平面按钮与堆栈面板的右侧对齐。


截至目前,它们都按照各自的顺序从左侧开始排列


为什么 XAML 没有识别出我的对齐方式?我能做点什么吗?


感谢你的帮助


这是我的代码


<StackPanel Grid.Row="2" Orientation="Horizontal" Margin="0,10,0,0">

                <GeometryButton    Command="{}" 

                                   Geometry="{StaticResource {}"

                                   ToolTip="{}"

                                   HorizontalAlignment="Left"/>


                <TextBlock 

                              Text="{}" 

                              Style="{}"

                              Margin="0,10,10,10"

                              Foreground="Black"

                              HorizontalAlignment="Left"/>



                <FlatButton Command="{}"

                               Content="{}" 

                               Style="{}"

                               VerticalAlignment="Center" 

                               HorizontalContentAlignment="Center"

                               IsDefault="True"

                               Margin="0"

                               MinWidth="80"

                               HorizontalAlignment="Right"

                               />


                <FlatButton Command="{}"

                               Content="{}" 

                               Style="{}"

                               VerticalAlignment="Center"

                               HorizontalContentAlignment="Center"

                               MinWidth="80"

                               Margin="10,0,0,0"

                               HorizontalAlignment="Right"

                               />

            </StackPanel>



慕侠2389804
浏览 57回答 1
1回答

慕运维8079593

如果您的预期输出是这样的:&nbsp;--------------------------------------| [Geo Button]&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|| [Text Block]&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;||&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;[Flat Button]||&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;[Flat Button]|&nbsp;--------------------------------------然后你需要Orientation将Vertical改为Horizontal。但是,如果您想要这样:&nbsp;--------------------------------------| [Geo Button]&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [Flat Button]|| [Text Block]&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [Flat Button]|&nbsp;--------------------------------------它是:更改 的 ,Margin同时Flat Button仍然使用上面的代码(我个人不推荐这样做);或者使用Grid或DockPanel,尝试在此处查找代码和更多说明我部分地实现了您的预期输出:<Grid Height="100" Background="Red">&nbsp; &nbsp; <Grid.ColumnDefinitions>&nbsp; &nbsp; &nbsp; &nbsp; <ColumnDefinition Width="*"/>&nbsp; &nbsp; &nbsp; &nbsp; <ColumnDefinition Width="*"/>&nbsp; &nbsp; </Grid.ColumnDefinitions>&nbsp; &nbsp; <StackPanel Orientation="Horizontal" Grid.Column="0">&nbsp; &nbsp; &nbsp; &nbsp; //...&nbsp; &nbsp; </StackPanel>&nbsp; &nbsp; <StackPanel Orientation="Horizontal" Grid.Column="1" HorizontalAlignment="Right">&nbsp; &nbsp; &nbsp; &nbsp; //...&nbsp; &nbsp; </StackPanel></Grid>部分地,因为我没有FlatButton和 的资源Geo Button,所以我只使用了常规的Button。请注意,您需要将VerticalAlignment属性设置为Centerfor <TextBlock>。
打开App,查看更多内容
随时随地看视频慕课网APP