如何在WPF中的XAML布局中实现在同一级别上有两个控件?
我正在尝试对标签、按钮和富文本框进行布局,这样标签和按钮将位于文本框的上方,但位于不同的侧面 我试过这个:如何在WPF中的XAML布局中实现在同一级别上有两个控件?,wpf,layout,Wpf,Layout,我正在尝试对标签、按钮和富文本框进行布局,这样标签和按钮将位于文本框的上方,但位于不同的侧面 我试过这个: <ScrollViewer Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="6"> <StackPanel> <DockPanel> <Label>some t
<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>
一些文本
x
因此:
我还认为它可能会起作用:
<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>
一些文本
x
但它没有:
使用标签很容易,而且我希望它在哪里,但是如何将按钮放在文本框右角上方呢?我也看过RenderTransform属性,但我不确定这是否是一个好的做法。尝试以下方法:
<ScrollViewer Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="6">
<StackPanel>
<Grid>
<RichTextBox Height="100px" ></RichTextBox>
<StackPanel Orientation="Horizontal" VerticalAlignment="Top">
<Label VerticalAlignment="Top">some text</Label>
<Button HorizontalAlignment="Right" Width="30px" VerticalAlignment="Top">x</Button>
</StackPanel>
</Grid>
</StackPanel>
</ScrollViewer>
一些文本
x