mardi 3 mars 2015

WPF move a path programmatically

What I have is a WINFORM with an element host that hosts a WPF user control. On the wpf user control I have a Path. What i want to do is move the path on the user control, according to strings that I read from a file. Meaning, I have a loop that reads a line from the file and according to that line, "moves" the path.


My problem is that the path isn't moving on the screen. All I have is the initial path and the last position.


The code on the winform:



private void WinForm_Method()
{
// This method invokes the method on the wpf user control

Type t = ElemHost.Child.GetType();
t.InvokeMember("MovePath", System.Reflection.BindingFlags.Default | System.Reflection.BindingFlags.InvokeMethod, null, ElemHost.Child, null);
}


The code on the wpf user control:



public void MovePath()
{
string line = null;

//Read data from file.
// Every line is of the format "M x1,y1 x2,y2 x3,y3 x4,y4 x1,y1"
using (StreamReader SR = new StreamReader("DataFile"))
{
while ((line = SR.ReadLine()) != null)
{
MyPath.Data = Geometry.Parse(line);
}
}
}

Aucun commentaire:

Enregistrer un commentaire