具有透明填充但实线描边的 WPF 形状可能吗?
WPF Shape With Transparent Fill But Solid Stroke Possible?
我正在尝试在我的 WPF 应用程序中创建一个具有透明填充但笔划为实心的形状。我只在我画的 Path
上看到一个名为 Opacity
的 属性,它将描边和填充都变为透明。是否可以只将填充透明而不将描边透明?
编辑:我需要填充为透明色,描边为纯色。
使用 SolidColorBrush
填充不透明度。
<Rectangle Stroke="Red" Margin="10" StrokeThickness="5" Height="50" Width="100">
<Rectangle.Fill>
<SolidColorBrush Color="Red" Opacity=".5"/>
</Rectangle.Fill>
</Rectangle>
如果您不需要绑定不透明度或颜色,您也可以使用 shorthand: Fill="#80FF0000"
其中前 2 个字符是 alpha 值的十六进制代码。
结果:
使用Polygon
class.
<Polygon Fill="Transparent" Points="1,2,35,50,90,20" Stroke="Aqua" StrokeThickness="2" />
如前所述,WPF 中有许多形状 here。
WPF provides a number of ready-to-use Shape objects. All shape objects inherit from the Shape class. Available shape objects include Ellipse, Line, Path, Polygon, Polyline, and Rectangle.
所以您想要透明填充而不是实心描边?为什么不这样做
<Rectangle Stroke="Red" StrokeThickness="5" Fill="Transparent"/>
我正在尝试在我的 WPF 应用程序中创建一个具有透明填充但笔划为实心的形状。我只在我画的 Path
上看到一个名为 Opacity
的 属性,它将描边和填充都变为透明。是否可以只将填充透明而不将描边透明?
编辑:我需要填充为透明色,描边为纯色。
使用 SolidColorBrush
填充不透明度。
<Rectangle Stroke="Red" Margin="10" StrokeThickness="5" Height="50" Width="100">
<Rectangle.Fill>
<SolidColorBrush Color="Red" Opacity=".5"/>
</Rectangle.Fill>
</Rectangle>
如果您不需要绑定不透明度或颜色,您也可以使用 shorthand: Fill="#80FF0000"
其中前 2 个字符是 alpha 值的十六进制代码。
结果:
使用Polygon
class.
<Polygon Fill="Transparent" Points="1,2,35,50,90,20" Stroke="Aqua" StrokeThickness="2" />
如前所述,WPF 中有许多形状 here。
WPF provides a number of ready-to-use Shape objects. All shape objects inherit from the Shape class. Available shape objects include Ellipse, Line, Path, Polygon, Polyline, and Rectangle.
所以您想要透明填充而不是实心描边?为什么不这样做
<Rectangle Stroke="Red" StrokeThickness="5" Fill="Transparent"/>