我试图放置一种由矩形制成的边框,并在其中添加标签和一些子弹装饰器。我需要将它们放在网格的特定行和列中以及顶部。
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="150" />
</Grid.ColumnDefinitions>
<!-- other controls in grid -->
<DockPanel Grid.Row="1" Grid.Column="1">
<Grid>
<Rectangle Width="120" Height="80" Fill="LightYellow" Stroke="Orange" StrokeThickness="2" RadiusX="8" RadiusY="8"/>
<Rectangle Width="120" Height="80" Fill="Transparent" Stroke="Orange" StrokeThickness="2" RadiusX="8" RadiusY="8">
<Rectangle.Effect>
<DropShadowEffect ShadowDepth="0" BlurRadius="15" Color="Orange"/>
</Rectangle.Effect>
<Rectangle.Clip>
<RectangleGeometry Rect="0,0,400,80" RadiusX="8" RadiusY="8"/>
</Rectangle.Clip>
</Rectangle>
<Grid>
<Label Content="Legend:"/>
<BulletDecorator Margin="5,20,0,0" VerticalAlignment="Top" >
<BulletDecorator.Bullet>
<Ellipse Height="8" Width="8" Fill="Blue"/>
</BulletDecorator.Bullet>
<TextBox TextWrapping="Wrap" Background="Transparent" Text="100 : Manager" BorderThickness="0" />
</BulletDecorator>
<BulletDecorator Margin="5,40,0,0" VerticalAlignment="Top" >
<BulletDecorator.Bullet>
<Ellipse Height="8" Width="8" Fill="Blue"/>
</BulletDecorator.Bullet>
<TextBox TextWrapping="Wrap" Background="Transparent" Text="200: Others" BorderThickness="0" />
</BulletDecorator>
</Grid>
</Grid>
</DockPanel>
</Grid>
标签和项目符号装饰器放置在网格行和列(1,1)的顶部,但边框不是矩形。我究竟做错了什么? Dockpanel似乎正确填充了网格中的整个空间(行= 1,列= 1)。
最佳答案
您需要将矩形的垂直对齐设置为顶部,以使其与Bullet装饰器匹配
关于wpf - 将Dockpanel内容置于顶部的网格内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45348024/