在 WPF 中匹配堆叠项目的大小
我有以下网格
。
<Grid DockPanel.Dock="Bottom">
<Border HorizontalAlignment="Stretch" VerticalAlignment="Stretch" CornerRadius="4" Background="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}">
<Border.RenderTransform>
<TranslateTransform X="2" Y="2" />
</Border.RenderTransform>
<Border.BitmapEffect>
<BlurBitmapEffect Radius="4" />
</Border.BitmapEffect>
</Border>
<Grid Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}">
<Image Source="{Binding Image}"></Image>
</Grid>
</Grid>
它渲染成这样。
请注意,第一个是水平的,而另一个是垂直的。
如何让 Border
与内部 Grid
大小相同?这样我就可以匹配投影。
I have the following Grid
.
<Grid DockPanel.Dock="Bottom">
<Border HorizontalAlignment="Stretch" VerticalAlignment="Stretch" CornerRadius="4" Background="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}">
<Border.RenderTransform>
<TranslateTransform X="2" Y="2" />
</Border.RenderTransform>
<Border.BitmapEffect>
<BlurBitmapEffect Radius="4" />
</Border.BitmapEffect>
</Border>
<Grid Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}">
<Image Source="{Binding Image}"></Image>
</Grid>
</Grid>
It renders like this.
Notice the first one is horizontal while the other is vertical.
How do I tell the Border
to be the same size as the inner Grid
? This is so that I can match the drop shadow.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会尝试以下操作:
干杯
I'd try the follows:
Cheers
您发布的代码对我来说效果很好,边框大小与内部网格的大小相匹配,因为它们都被拉伸以适合外部网格的大小。
如果您的外部网格无论如何都是固定尺寸,并且您的内部图像是可变尺寸,您可能需要考虑将边框移动到内部网格并将其水平/垂直对齐设置为居中,这样它就不会拉伸以填充它的内容
The code you posted works fine for me, the border size matches the inner Grid's size, because they are both stretched to fit the Outer Grid's Size.
If your outer Grid is a set size no matter what, and your inner Image is a variable size, you might want to consider moving your Border into the Inner Grid and setting it's Horizontal/Vertical alignment to Center so it doesn't stretch to fill it's contents