【发布时间】:2021-07-04 14:18:59
【问题描述】:
我正在尝试对标签、按钮和富文本框进行布局,以便标签和按钮位于文本框上方但位于不同的侧面。
我试过了:
<ScrollViewer Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="6">
<StackPanel>
<DockPanel>
<Label>some text</Label>
<Button DockPanel.Dock="Right" Width="30px">x</Button>
</DockPanel>
<RichTextBox Height="100px"></RichTextBox>
</StackPanel>
</ScrollViewer>
我也认为它可能会起作用:
<ScrollViewer Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="6">
<StackPanel>
<StackPanel Orientation="Horizontal" FlowDirection="LeftToRight">
<Label>some text</Label>
<StackPanel Orientation="Horizontal" FlowDirection="RightToLeft">
<Button HorizontalAlignment="Right" Width="30px">x</Button>
</StackPanel>
</StackPanel>
<RichTextBox Height="100px"></RichTextBox>
</StackPanel>
</ScrollViewer>
使用标签很容易,它是我想要的位置,但是我该怎么做才能将按钮放在文本框右上角的上方?我也见过 RenderTransform 属性,但我不确定这是否是一个好习惯。
【问题讨论】: