ObservableCollection w/ DataGrid TwoWay


i have 2 problems in example below.

1. can't seem twoway binding on datagrid observablecollection (or binding matter). denoted in code comments.

2. can see, move thumb, have manually update rectangle's position, linesegment's point, , corresponding pointlist's point. i've been trying apply databinding automatically tie these values together, can't seem working. example hard-coded, have dynamic example 1000s of points on slow side. hope databinding speed on manual updating of points.  going first problem, when x or y value changed in datagrid, need linked/databound objects update.. need thumb move, pointlist update, , segment move.

is possible? can show me how link of these manual updates can rest? thanks.

<usercontrol xmlns:my="clr-namespace:system.windows.controls;assembly=system.windows.controls.data" x:class="layouttests.hittestandscale"
xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation
xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
background="#e3e3e3">

<grid x:name="layoutroot">

<grid.columndefinitions>
<columndefinition width="100"></columndefinition>
<columndefinition width="*"></columndefinition>
</grid.columndefinitions>

 

<stackpanel verticalalignment="top" grid.column="0">

<my:datagrid x:name="dg" width="100" height="300" autogeneratecolumns="false">

<my:datagrid.columns>
<my:datagridtextcolumn header="x" displaymemberbinding="{binding x, mode=twoway}" />
<my:datagridtextcolumn header="y" displaymemberbinding="{binding y}" />
</my:datagrid.columns>

</my:datagrid>

</stackpanel>

<scrollviewer grid.column="1" verticalalignment="center" horizontalalignment="center" verticalscrollbarvisibility="auto" horizontalscrollbarvisibility="auto">

<grid >

<canvas x:name="c1_outter" width="300" height="300" verticalalignment="top" horizontalalignment="left"></canvas>
<canvas x:name="c1" width="300" height="300" verticalalignment="top" horizontalalignment="left" background="#ffdadada">

<canvas.rendertransform>
<scaletransform x:name="zoom"></scaletransform>
</canvas.rendertransform>

</canvas>

</grid>
</scrollviewer>

</grid>
</
usercontrol>

public partial class hittestandscale : usercontrol

{

observablecollection<point> pointlist;
path path;
public hittestandscale()

{

initializecomponent();
pointlist =
new observablecollection<point>();
path =
new path()

{

stroke =
new solidcolorbrush(colors.black),
strokethickness = 1,

};

pathgeometry geo = new pathgeometry() { figures = new pathfigurecollection() };
pathfigure pf = new pathfigure() { segments = new pathsegmentcollection() };

pf.startpoint = new point(10, 10);
pointlist.add(
new point(10, 10));linesegment ls1 = new linesegment() { point = new point(100, 150) };
linesegment ls2 = new linesegment() { point = new point(200, 10) };

pf.segments.add(ls1);
pf.segments.add(ls2);

pointlist.add(
new point(100, 150));
pointlist.add(
new point(200, 10));

geo.figures.add(pf);

path.data = geo;

c1.children.add(path);

rectangle thumb = new rectangle();
thumb.height = 10;
thumb.width = 10;
thumb.fill =
new solidcolorbrush(colors.white);
thumb.mouseleftbuttondown += new mousebuttoneventhandler(thumb_mouseleftbuttondown);
thumb.mouseleftbuttonup +=
new mousebuttoneventhandler(thumb_mouseleftbuttonup);
thumb.mousemove +=
new mouseeventhandler(thumb_mousemove);
thumb.setvalue(
canvas.topproperty, pointlist[1].y - thumb.height / 2);
thumb.setvalue(
canvas.leftproperty, pointlist[1].x - thumb.width / 2);

c1.children.add(thumb);
dg.itemssource = pointlist;

}

bool movingthumb;

rectangle mobilethumb;

void thumb_mousemove(object sender, mouseeventargs e)
{

if (movingthumb && mobilethumb != null)
{

point mousepoint = e.getposition(c1);
mobilethumb.setvalue(
canvas.topproperty, mousepoint.y - mobilethumb.height / 2);
mobilethumb.setvalue(
canvas.leftproperty, mousepoint.x - mobilethumb.width / 2);
((
linesegment)((pathgeometry)path.data).figures[0].segments[0]).point = new point(mousepoint.x, mousepoint.y);

//problem 1 here, error occurs when uncomment this
//pointlist[1] = new point(mousepoint.x, mousepoint.y);

}

}

void thumb_mouseleftbuttonup(object sender, mousebuttoneventargs e)

{

if (movingthumb)
{
movingthumb = false;
mobilethumb.releasemousecapture();
mobilethumb =
null;

}

}

void thumb_mouseleftbuttondown(object sender, mousebuttoneventargs e)

{

if (!movingthumb)
{

if (sender is rectangle)
{

mobilethumb = (rectangle)sender;
movingthumb =
true;
mobilethumb.capturemouse();

}

}

}

}

 

have implimented inotifypropertychanged interface dataobejct (i saw it's point object, of course not)?

using observablecollection affect binding when add/remove items list . using observablecollection not need reset binding list or datagrid when collection changed (not item inside collection changed). not have effect when data object properties changed. need implement inotifypropertychanged interface dataobject.



Silverlight  >  Programming Silverlight with .NET – General



Comments

Popular posts from this blog

Conditional formatting a graph vertical axis in SSRS 2012 charts

Register with Power BI failed

SQL server replication error Cannot find the dbo or user defined function........