Draw a rectangle above the image

I want to draw a rectangle over one Image .

For example, I have the following (white and black) profile of the vessel, and I want to add some (yellow and red) rectangles above this profile in certain places:

enter image description here

Is it possible? How can i do this?

+5
source share
2 answers

It is very possible if you know the x, y, width and height of the areas you want to select, you can put all the controls in the canvas.

You can set the properties in the rectangles in the code like this:

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);

and if you want to add them to xaml you might like this.

<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>
+9
source

Try this, it will also help you.

<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>

It is displayed as follows

Result

+1

All Articles