WPF边框厚度增加方向

发布于 2024-08-28 17:04:17 字数 453 浏览 3 评论 0原文

嘿。另一个 WPF 问题。在我的 XAML 代码中,我有一个边框:

<Border x:Name="myBorder" Background="AliceBlue" 
    Width="200" Height="200" 
    BorderThickness="10" BorderBrush="Black">
</Border>

在代码中的某处,我增加了 BorderThickness

double thickness = myBorder.BorderThickness.Bottom + 2;
myBorder.BorderThickness = new Thickness(thickness);

,结果是边框的权重增加,但不是在 200x200 宽度-高度之外,而是在内部,从而减小了尺寸。有没有办法做到相反?

Hey. Another WPF question. In my XAML code I have a border:

<Border x:Name="myBorder" Background="AliceBlue" 
    Width="200" Height="200" 
    BorderThickness="10" BorderBrush="Black">
</Border>

and somewhere in code I increase the BorderThickness

double thickness = myBorder.BorderThickness.Bottom + 2;
myBorder.BorderThickness = new Thickness(thickness);

and the result is that the border's weight increases but not outside the 200x200 width-height, but inner, decreasing the dimension. Is there a way to do the opposite?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冬天旳寂寞 2024-09-04 17:04:17

好吧,实际上您应该在边框的内部或外部控件上设置宽度和高度,而不是在边框本身上。然后可以为边框设置负边距,等于减去边框厚度的值。像这样的事情应该达到目的:

<Border x:Name="myBorder" Background="AliceBlue" 
Margin="-10,-10,-10,-10" BorderThickness="10" BorderBrush="Black">
    <Button Background="Red" Content="Test" Width="200" Height="200"></Button>
</Border>

Well, actually you should set the width and height on the inner or outer control of the border, not on the border itself. Then you can set a negative margin for the border, equal to minus the value of the border thickness. Something like this should to the trick:

<Border x:Name="myBorder" Background="AliceBlue" 
Margin="-10,-10,-10,-10" BorderThickness="10" BorderBrush="Black">
    <Button Background="Red" Content="Test" Width="200" Height="200"></Button>
</Border>
ぃ双果 2024-09-04 17:04:17

看来您需要相应地增加宽度和高度。

It looks like you need to increase Width and Height accordingly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文