c# - Windows Phone: How to draw a line on a Rectangle? -


i draw rectangle , need divide rectangle 2 parts. trying use line in order divide dont know why can not see line.

rectangle rect = new rectangle(); rect.fill= colors.blue; rect.width=100; rect.margin = new thikness (0,40,0,0); grid.children.add(rect);  line line = new line(); line.stroke = colors.black; line.strokethickness=1; line.x1=2;  line.x2=7; line.y1=41; line.y2=41;  grid.children.add(line); 

do have idea how can add line on rectangle?

here how divide vertically:-

a) drawing line 5 pixels in width not visible because line of stroke black , page background black line hidden. line drawn (2,41) (7,41).

b) rectangle in center of page, 100 pixels wide , tall page , line on top left did not intersect rectangle in center

c) recommend use of canvas since can set top , left pixel positions of each item on canvas

i modified code in following way:-

rectangle rect = new rectangle(); rect.fill = new solidcolorbrush(colors.blue); rect.width = 100; rect.height = 200; canvas.setleft(rect, 200); canvas.settop(rect, 20); layoutroot.children.add(rect);  line line = new line(); line.stroke = new solidcolorbrush(colors.white); line.strokethickness = 1;  line.x1 = canvas.getleft(rect) + rect.width / 2; line.x2 = canvas.getleft(rect) + rect.width / 2;  line.y1 = canvas.gettop(rect); line.y2 = canvas.gettop(rect) + rect.height;  layoutroot.children.add(line); 

1) layoutroot canvas in xaml...i have changed grid canvas in default page template.

2) have used these 2 lines set position of rect on canvas. can change hardcoded/programmatically calculated value.

canvas.setleft(rect, 200); canvas.settop(rect, 20); 

3) have calculated x , y positions of line here

line.x1 = canvas.getleft(rect) + rect.width / 2; line.x2 = canvas.getleft(rect) + rect.width / 2;  line.y1 = canvas.gettop(rect); line.y2 = canvas.gettop(rect) + rect.height; 

the x1 , x2 positions left position of rect plus half of rect width

the y1 , y2 positions rect top , rect top plus rect height.

add these 2 elements canvas , work


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -