在WPF中,如何设置外部,居中和内部边界? [英] In WPF, how to set an outer, centered, and inner border?
本文介绍了在WPF中,如何设置外部,居中和内部边界?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如,当我为按钮设置边框时,它是外部边框.但是,如果我希望它居中或位于内部,最简单的方法是什么?
When I set a border for a button, for example, it is an outer border. But What if I would want it to be centered or inner, what would be the simplest way?
这是我的意思:
推荐答案
因此,为了重新创建示例,这里提供了quickie概念示例替代方法.但是,可以通过多种不同的方法来实现相同的效果,但这至少是其中的几种...
So to re-create your example, here's quickie concept example alternatives. However there's a bunch of different ways you can accomplish the same effects but here's at least a few...
<StackPanel>
<StackPanel.Resources>
<Style TargetType="Border">
<Setter Property="BorderBrush" Value="#570000FF"/>
<Setter Property="BorderThickness" Value="10"/>
<Setter Property="Height" Value="50"/>
<Setter Property="Width" Value="100"/>
<Setter Property="Margin" Value="10"/>
</Style>
<Style TargetType="Rectangle">
<Setter Property="Stroke" Value="Black"/>
<Setter Property="StrokeThickness" Value="1"/>
</Style>
</StackPanel.Resources>
<Border>
<Rectangle/>
</Border>
<Border>
<Rectangle Margin="-5"/>
</Border>
<Border BorderBrush="Black" BorderThickness="1">
<Rectangle Stroke="#570000FF" StrokeThickness="10"/>
</Border>
</StackPanel>
结果:
希望这会有所帮助,欢呼起来.
Hope this helps, cheers.
这篇关于在WPF中,如何设置外部,居中和内部边界?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文