- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm planing with PaletteSet and I want to remember is the user close or not the PaletteSet, so the next time AutoCAD opens the PaletteSet is in the same state as before.
I found the PaletteSet have the Load and Save event that have access to PalettePersistEventArgs with the ConfigurationSection.
I didn't found a way to get the ConfigurationSection from the PaletteSet without using the events.
In the end I'm using the Application.UserConfigurationManager.OpenCurrentProfile() to save and load the visibility of the PaletteSet.
Here is my PaletteSetUtils class to help create PaletteSet.
public static class PaletteSetUtils
{
public static PaletteSet Create(string title, Guid guid, System.Windows.Media.Visual visual, bool defaultVisible = true)
{
var paletteSet = new PaletteSet(title, guid);
paletteSet.MinimumSize = new System.Drawing.Size(300, 300);
paletteSet.DockEnabled = DockSides.Right | DockSides.Left;
paletteSet.Dock = DockSides.Right;
paletteSet.Style = PaletteSetStyles.ShowAutoHideButton
| PaletteSetStyles.ShowCloseButton
| PaletteSetStyles.ShowPropertiesMenu
| PaletteSetStyles.Snappable;
paletteSet.Save += PaletteSet_Save;
paletteSet.AddVisual(title, visual);
paletteSet.LoadVisible(defaultVisible);
return paletteSet;
}
private static string GetConfigurationVisibleKey(this PaletteSet paletteSet)
{
return $"{paletteSet.GetType().Name}.{paletteSet.Name}.Visible";
}
private static void LoadVisible(this PaletteSet paletteSet, bool defaultVisible = true)
{
var configurationSection = Application.UserConfigurationManager.OpenCurrentProfile();
var visible = (bool)configurationSection.ReadProperty(paletteSet.GetConfigurationVisibleKey(), defaultVisible);
paletteSet.Visible = visible;
}
private static void SaveVisible(this PaletteSet paletteSet)
{
var configurationSection = Application.UserConfigurationManager.OpenCurrentProfile();
configurationSection.WriteProperty(paletteSet.GetConfigurationVisibleKey(), paletteSet.Visible);
}
private static void PaletteSet_Save(object sender, PalettePersistEventArgs e)
{
var paletteSet = (PaletteSet)sender;
paletteSet.SaveVisible();
}
public static void ToggleVisible(this PaletteSet paletteSet)
{
paletteSet.Visible = !paletteSet.Visible;
}
}
With something like this:
public class AppPalette : IExtensionApplication
{
public void Initialize()
{
PaletteSetUtils.Create("Test", new Guid("00000000-0000-0000-0000-000000000000"), new Grid());
}
public void Terminate() { }
}
The code works, but I would prefer to use PalettePersistEventArgs.ConfigurationSection.
If someone know how to do it would be great.
Another question would be:
- How to change the title of the PaletteSet after created.
- How to find all PaletteSet already register inside AutoCAD.
Thanks
Solved! Go to Solution.