i adding rectangle
grid cell values being entered user directly in grid rows. when modify value of specific column thickness
i.e height
then increases height
of selected row rectangle doesnt rearrange rectangle below after selected row rectangle.
in xaml.cs
public class mylayer : inotifypropertychanged { public string thickness { get; set; } public string offsetright { get; set; } public string offsetleft { get; set; } public string material { get; set; } public string materialpopup { get; set; } public rectangle rectangle { get; set; } public glassrectangle glassrectangle { get; set; } public materiallayer() { glassrectangle = new glassrectangle(); } event propertychangedeventhandler inotifypropertychanged.propertychanged { add { } remove { } } } public class glassrectangle { public rectangle rectangle { get; set; } public double top = 0; public glassrectangle() { rectangle = new rectangle(); } } private void gridinner_cellvaluechanged(object sender, devexpress.xpf.grid.cellvaluechangedeventargs e) { string cellvalue = string.empty; mylayer currentlayer = ((mylayer)(e.row)); if (e.column.headercaption.tostring() == "thickness") { cellvalue =(e.value.tostring()); //there alredy rectangle - means edit mode if (currentlayer.rectangle != null) { currentlayer.rectangle.height = convert.todouble(cellvalue); currentlayer.rectangle.stroke = new solidcolorbrush(color.fromrgb(0, 255, 0)); } //else insert mode else { currentlayer.rectangle = createrectangle(cellvalue); } } } protected rectangle createrectangle(string cellval) { rectangle newrect = new rectangle(); newrect.stroke = brushes.red; newrect.strokethickness = 1; if (cellval.tostring().contains(".")) { newrect.height = convert.todouble(cellval) * 100; } else { newrect.height = convert.todouble(cellval); } newrect.width = width; canvas.setleft(newrect, 100); double canvastop = 0.0; if (canvasboard.children.count > 0) { var lastchildindex = canvasboard.children.count - 1; var lastchild = canvasboard.children[lastchildindex] frameworkelement; if (lastchild != null) //lastchild.height-1: come extactly on existing if set +1 comes below first rectangle canvastop = canvas.gettop(lastchild) + lastchild.height - 1; } canvas.settop(newrect, canvastop); val = val + 1; newrect.tag = val; canvasboard.children.add(newrect); //rectangle = rect; foreach (uielement ui in canvasboard.children) { if (ui.gettype() == typeof(rectangle)) { itemstoremove.add(ui); } } return newrect; }
new event method:
private void gridmaterialinner_cellvaluechanged(object sender, devexpress.xpf.grid.cellvaluechangedeventargs e) { string cellvalue = string.empty; string celloldvalue = string.empty; mylayer currentlayer = ((mylayer)(e.row)); if (e.column.headercaption.tostring() == "thickness") { //current cell value cellvalue =(e.value.tostring());// getrowcellvalue(e.rowhandle, gridmaterialinner.columns["lastname"]).tostring(); //there alredy rectangle - means edit mode double currentheight = 0.0; double oldht = 0.0; // old cell value if (e.oldvalue != null) { celloldvalue = (e.oldvalue.tostring()); } if (currentlayer.rectangle != null) { if (cellvalue.tostring().contains(".")) { currentheight = convert.todouble(cellvalue) * 100; } else { currentheight = convert.todouble(cellvalue) * 100; } if (celloldvalue.tostring().contains(".")) { oldht = convert.todouble(celloldvalue) * 100; } else if(celloldvalue!=string.empty) { oldht = convert.todouble(celloldvalue) * 100; } currentlayer.rectangle.height = currentheight; currentlayer.rectangle.stroke = new solidcolorbrush(color.fromrgb(0, 255, 0)); //refresh(); //get index of selected row int layerindex = materialbindlist.indexof(currentlayer); for(int = layerindex; < materialbindlist.count-1; i++) { //set top position of other rectangles below selected rectangle/row //(current-old)+top canvas.settop(materialbindlist[i + 1].rectangle, (currentheight - oldht) + materialbindlist[i + 1].glassrectangle.top); //canvas.settop(materialbindlist[i].rectangle, (currentheight - oldht) + materialbindlist[i + 1].glassrectangle.top); } } //else insert mode else { //materiallayer object currentlayer.rectangle = createrectangle(cellvalue); //store top & rectangle object in glassrectangle class referenced in materiallayer class currentlayer.glassrectangle.rectangle = currentlayer.rectangle; currentlayer.glassrectangle.top = canvastop; } } }
this create rectangle 1 after other stacked item on canvas. when modify value of thickness
column height
of rectangle
reflects on canvas other rectangle below must appear after changed height of current rectangle.
note: cant use wrappanel in application. modify existing code using canvas.
help appreciated!
modified loop in cellchange event:
int layerindex = materialbindlist.indexof(currentlayer); for(int = layerindex; < materialbindlist.count-1; i++) { //set top position of other rectangles below selected rectangle/row //(current-old)+top double top=convert.todouble((currentheight - oldheight) + materialbindlist[i + 1].glassrectangle.top); canvas.settop(materialbindlist[i + 1].rectangle,top); materialbindlist[i + 1].glassrectangle.top = top; }
what you're looking can done canvas
should consider using itemscontrol
this.
solution when forced use canvas
:
private void refresh() { (int = 1; < canvasboard.children.count; ++i) { var currentelement = canvasboard.children[i] frameworkelement; var previouselement = canvasboard.children[i - 1] frameworkelement; if (currentelement == null || previouselement == null) return; var requiredtop = canvas.gettop(previouselement) + previouselement.height - 1; if (math.abs(canvas.gettop(currentelement) - requiredtop) > 0.0) canvas.settop(currentelement, requiredtop); } }
now call function "after" change size of existing element in canvas
, re-position elements accordingly suit new dimension. in code, called gridinner_cellvaluechanged(...)
function after set new height in "edit" mode.
what should try do:
if able persuade whoever need , use itemscontrol
, simpler.
say rough example:
xaml be:
<itemscontrol itemssource="{binding items}"> <itemscontrol.itemspanel> <itemspaneltemplate> <virtualizingstackpanel orientation="vertical" /> </itemspaneltemplate> </itemscontrol.itemspanel> </itemscontrol>
with items
declared public observablecollection<rectangle> items { get; set; }
in code.
now add()
function be:
private void add() { var rect = new rectangle { stroke = brushes.red, strokethickness = 1, height = convert.todouble(txtheight.text), width = 100 }; items.add(rect); }
and updates when editing existing control's automatic in case. there no hard-coded positioning layout container takes care of mess you.
you can ofcourse switch items
collection type own custom control type mylayer
, implementing inpc, changes still continue automatic. you'd have define datatemplate
item rendered that's 3 lines of work in xaml.
you can work of items
property directly when needing tweak exisiting control having reference itemscontrol
in code-behind. binding's should take care of updates view automatically.
Comments
Post a Comment