【发布时间】:2019-10-04 10:01:53
【问题描述】:
我希望我的 UserControl 具有黑色背景。小事情是我希望它从侧面有一些偏移。
我是这样做的:
<UserControl x:Class="PitramVisionPlayerUI.Controls.Readout"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="50" d:DesignWidth="200">
<UserControl.Background>
<DrawingBrush Stretch="Fill">
<DrawingBrush.Drawing>
<GeometryDrawing>
<GeometryDrawing.Geometry>
<PathGeometry>
<PathFigure IsClosed="True" StartPoint="0.1,0.1">
<PathFigure.Segments>
<LineSegment Point="0.9,0.1" />
<LineSegment Point="0.9,0.9" />
<LineSegment Point="0.1,0.9" />
</PathFigure.Segments>
</PathFigure>
</PathGeometry>
</GeometryDrawing.Geometry>
<GeometryDrawing.Brush>
<SolidColorBrush Color="Black"></SolidColorBrush>
</GeometryDrawing.Brush>
</GeometryDrawing>
</DrawingBrush.Drawing>
</DrawingBrush>
</UserControl.Background>
</UserControl>
问题是它不起作用。它不断填充整个矩形。如果我将 DrawingBrush 的属性 Stretch 从“Fill”替换为“None”,我的 UserControl 中间会出现一个黑点。
【问题讨论】:
-
偏移应该有什么背景?你不能在消费视图中设置
UserControl的Margin吗?<local:Readout Margin="10" />
标签: wpf