开发者

WPF: copying of XmlElement

开发者 https://www.devze.com 2022-12-14 19:12 出处:网络
I create a window in WPF.The constructor takes a \"ref XmlElement settings\" which is used to display information in that window.

I create a window in WPF. The constructor takes a "ref XmlElement settings" which is used to display information in that window.

In the constructor, I clone those settings:

_ClonedSettings = (XmlElement)settings.Clone();

and I keep a pointer to the original settings:

_OriginalSettings = settings;

The UI modifies _ClonedSettings开发者_如何学Python. Then if user hits OK button, I want to overwrite the original settings with the _ClonedSettings, so the window creator gets the right values.

How do I do this final copying operation?


Don't use a ref. Just set the settings as a public property on the window

public class SettingsEditor : Window
{ 
  public XmlElement Settings {get;set;}
  /*...*/
}

Within the Window, update the settings and such as you've done. Once the window has been shown, get the settings out.

/*...*/
var editor = new SettingsEditor { Settings = settings };
editor.ShowDialog();
settings = editor.Settings;
/*...*/

You can also set a DialogResult on your window to see what happened with the editor...

0

精彩评论

暂无评论...
验证码 换一张
取 消