Well, in those days I figured out the answer myself. I continued to use the Square
user control and used it in the layout.
On building x / y positions, I used this:
Point point = myElement.TransformToVisual(App.Current.RootVisual as FrameworkElement)).Transform(new Point(0, 0));
There was a failure in saving the XML file because silverlight 4 does not provide elevated privileges for the application in the browser. But then I used this on my save button click event:
SaveFileDialog dlgSave = new SaveFileDialog(); dlgSave.DefaultExt = "xml"; dlgSave.Filter = "XML Files (XML)|*.xml;"; dlgSave.FilterIndex = 1; strXML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + myXML.ToString();//myXML is the XDocument I created globally and saved data in it try { bool check = (bool)dlgSave.ShowDialog(); if (check) { using (Stream stream = dlgSave.OpenFile()) { StreamWriter sw = new StreamWriter(stream, System.Text.Encoding.UTF8); sw.Write(strXML); sw.Close(); stream.Close(); } MessageBox.Show("XML Saved successfully"); } catch (SecurityException) { MessageBox.Show("There seems to be an issue with saving XML file on the disk, please try again...", "Something not right", MessageBoxButton.OK); } catch (UnauthorizedAccessException) { MessageBox.Show("Saving here requires authorised permissions", "Access Denied", MessageBoxButton.OK); }
source share