What's new
  • Visit Rebornbuddy
  • Visit Panda Profiles
  • Visit LLamamMagic
  • Visit Resources
  • Visit Downloads
  • Visit Portal

¿How do I preserve a user-setting?

Elektrozoider

Member
Joined
Jun 4, 2015
Messages
114
Reaction score
10
Taking this simplified IPlugin interface as example:

Code:
namespace Test {
    public sealed class Plugin : IPlugin {
        public static VirtualKeys key = VirtualKeys.MouseButtonMiddle;
    }
}

With this simplified Config.cs:

Code:
namespace Test {

    public partial class Config {

        public static Window GetDisplayWindow() {
            try {
                // ...
                UserControl mainControl = (UserControl)XamlReader.Load(new MemoryStream(Encoding.UTF8.GetBytes(xamlContent)));
                Window window = new Window();
                window.Content = mainControl;
                // ...
                ComboBox cb = (ComboBox)mainControl.FindName("CB_KEY");
                // ...
                window.ContentRendered += delegate {
                    cb.SelectedItem = Plugin.key.ToString();
                };
                // ...
                cb.SelectionChanged += delegate {
                    Plugin.key = (VirtualKeys)Enum.Parse(typeof(VirtualKeys), cb.SelectedItem.ToString());
                };
             
                return window;
             
            } catch (Exception ex) {
                log.Error("[Test] Error opening Config window: " + ex);
                return null;
            }
        }
    }
}

The thing is that I would like to preserve the item that the user has selected in the ComboBox, instead of always loading the default initial value (VirtualKeys.MouseButtonMiddle) on next DemonBuddy startups. ¿How could I do this?.

I mean, not sure how to use the settings infrastructure in the way that DemonBuddy compiles the source-files at runtime. So by the moment I'm using Xml serialization.
 
Last edited:
Back
Top