wpf - 将Dockpanel内容置于顶部的网格内

标签 wpf xaml mvvm grid dockpanel

我试图放置一种由矩形制成的边框,并在其中添加标签和一些子弹装饰器。我需要将它们放在网格的特定行和列中以及顶部。

<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/

相关文章:

c# - 带有转换器的 WPF 单选按钮 - 我的所有角色如何变成女性

c# - XamlWriter.Save() 没有序列化 DependencyProperties

wpf - Windows 窗体是旧技术吗?

android - 按钮文本始终以大写形式显示

xaml - 绑定(bind)后转换器返回 Segoe MDL2 图标不起作用

c# - 在 MVVM WPF 中将 DataTable 绑定(bind)到 DataGrid

c# - 与 Caliburn Micro 问题的深度属性绑定(bind)

WPF 应用程序退出时清理

wpf - 如何淡化 WPF 背景图像?

.net - 从 DataTemplate 访问父 DataContext