答案 0 :(得分:10)
如果您知道要突出显示的区域的x,y,宽度和高度,则很可能将所有控件放入画布中。
您可以在代码后面的矩形中设置属性,如下所示:
Rectangle rectangle = new Rectangle();
rectangle.SetValue(Canvas.LeftProperty, 10);
rectangle.SetValue(Canvas.TopProperty, 10);
rectangle.Width = 1000;
rectangle.Height = 50;
rectangle.Fill = new SolidColorBrush() { Color = Colors.Red, Opacity = 0.75f };
canvas.Children.Add(rectangle);
如果你想在xaml中添加它们,你可以这样。
<Canvas>
<Image Source="..."/>
<Rectangle Canvas.Left="10" Canvas.Top="10" Width="1000" Height="50">
<Rectangle.Fill>
<SolidColorBrush Color="Red" Opacity="0.75"/>
</Rectangle.Fill>
</Rectangle>
</Canvas>
答案 1 :(得分:3)
试试这个也会对你有帮助。
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="Multi_Textbox.Window1"
x:Name="Window"
Title="Window1"
Width="640" Height="480">
<Grid x:Name="LayoutRoot">
<Image Margin="104,50,75,99" Source="barkship.jpg"/>
<Rectangle Fill="#FF28B0DE" HorizontalAlignment="Left" Height="17.334" Margin="212,0,0,111.333" Stroke="Black" VerticalAlignment="Bottom" Width="99.667"/>
<TextBlock HorizontalAlignment="Left" Height="11" Margin="230.667,0,0,115" TextWrapping="Wrap" Text="CHANDRU" VerticalAlignment="Bottom" Width="63.333" Foreground="White"/>
</Grid>
它的输出就像这样