开发者

like exec command in silverlight(save and load properties of Elements dynamically)

i have some element in my container and want to save all properties of this elements. i list this element by VisualTreeHelper and save its attributes in DB, question is that how to retrieve this properties and affect them? i think that The Silverlight have some statement that behave like Exec in Sql-Server.

i save properties in one line that delimited by semicolon.(if you have any suggestion ,appreciate)

Edit: suppose this scenario: End-User choose a tool from Mytoolbox(a container like Grid) ,a dialog shown its properties for creation and finally draw Grid . in resumption he/she choose one element(like Button) and drop it on one of the grid's cell. now i want to save workspace that he/she created! My RootLayout have one container control so any of element are child of this.HERETOFORE i want create one string that contain all开发者_Python百科 general properties(not all of them) and save to DB, and when i load this control, i create an element by the type that i saved and affect it by the properties that i saved; with something like EXEC command.

is this possible ? have you new approach for this scenario(Guide me with example please).

FINAL ANSWER HERE


You might want to try Isolated File Storage, where you can save/load your settings to the local hard drive. Doing so is very easy, just a few lines of code.

i think that The Silverlight have some statement that behave like Exec

No it doesn't :)

Edit: ok, here is a guideline on how you might go about applying your locally saved settings to your UI elements.

First up, decide on an interface that your settable controls will implement:

public interface IMySettableSettingsControl
{
    Dictionary<string, object> RetrieveSettings();
    void ApplySettings(Dictionary<string, object> settings);
}

Now add this interface to your controls that will persist their settings locally:

public MyControl : IMySettableSettingsControl 
{
    public void ApplySettings(Dictionary<string, object> settings) 
    {
        if (settings.Key.Contains("TextboxContents"))
            someTextBox.Text = (string) settings["TextboxContents"];

        if (settings.Key.Contains("Height"))
            this.Height = (double) settings["Height"];

        ((IMySettableSettingsControl) someChildControl).ApplySettings( (Dictionary<string, object>) settings["MyChildControl"])
    }

    public Dictionary<string, object> RetrieveSettings()
    {
        Dictionary<string, object> localSettings = new Dictionary<string, object>();
        localSettings.Add("Height", this.Height);
        localSettings.Add("TextboxContents", someTextBox.Text);

        localSettings.Add("MyChildControl", ((IMySettableSettingsControl) someChildControl).RetrieveSettings();
    }
}

Of course you can get as fancy as you like with this - what i have illustrated above is simply an example. What i have done in the past is have my MainPage.cs file load the settings from Isolated Storage, and then pass the Dictionary in on the constructor of each controller it creates, each controller will then pass it on to each view it creates. To save the settings, i handle the Exit event of the Application:

Application.Current.Exit += new EventHandler(Current_Exit);

and then in the handler:

private void Current_Exit(object sender, EventArgs e)
{
    Dictionary<string, object> settings = new Dictionary<string, object>();

    //call each UI control or controller, passing in the settings object

    //now i can persist the settings dictionary to IsolatedStorage
}

Of course when i do this i use a custom data object for persisting my settings, and i have the option of calling a webservice to retrieve default settings if a local instance is not found (or is found to be corrupt, because the saving of it was interrupted for some reason).

So take the above example, slice it and dice it and change it to suit your needs. Hope it helps.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜