绘制布局(网格、画布等),以便一个或多个单元格包含限制区域。然后在特定区域上绘制一个矩形或边框控件,以获得所需的效果。记得先添加矩形,或者像我在下面展示的那样使用ZIndex,这样代码就不会隐藏任何控件。
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Rectangle Grid.Column="0" Grid.Row="1" Panel.ZIndex="0" >
<Rectangle.Style>
<Style TargetType="{x:Type Rectangle}">
<Setter Property="Fill" Value="Blue"/>
</Style>
</Rectangle.Style>
</Rectangle >
<TextBox Grid.Column="0" Grid.Row="1" Height="25" Margin="10" Text="Test 123" Panel.ZIndex="1" />
</Grid>