private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     //save settings
     try
     {
         if (SetToolSettings())
         {
             if (ElevationCreatorSettingStorageUtil.StoreElevationCreatorSettings(m_doc, toolSettings))
             {
                 //saved settings.
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Failed to save settings to extensible storage.\n" + ex.Message, "Elevatino Creator: Save Settings", MessageBoxButton.OK, MessageBoxImage.Warning);
     }
 }
        private void GetToolSettings()
        {
            try
            {
                toolSettings = ElevationCreatorSettingStorageUtil.GetElevationCreatorSettings(m_doc);
                radioBttnRoomLink.IsChecked = toolSettings.IsLinkedRoom;
                radioBttnWallLink.IsChecked = toolSettings.IsLInkedWall;

                for (int i = 0; i < comboBoxViewFamily.Items.Count; i++)
                {
                    ViewFamilyType vft = comboBoxViewFamily.Items[i] as ViewFamilyType;
                    if (vft.Id.IntegerValue == toolSettings.ViewFamilyId)
                    {
                        comboBoxViewFamily.SelectedIndex = i; break;
                    }
                }

                for (int i = 0; i < comboBoxViewTemplate.Items.Count; i++)
                {
                    ViewTemplateProperties vtp = comboBoxViewTemplate.Items[i] as ViewTemplateProperties;
                    if (vtp.TemplateId.IntegerValue == toolSettings.ViewTemplateId)
                    {
                        comboBoxViewTemplate.SelectedIndex = i; break;
                    }
                }

                radioBttnTemplate.IsChecked    = toolSettings.ScaleByTemplate;
                textBoxScale.Text              = toolSettings.CustomScale.ToString();
                textBoxSpace.Text              = toolSettings.SpaceAround.ToString();
                checkBoxA.IsChecked            = toolSettings.AIsSelected;
                checkBoxB.IsChecked            = toolSettings.BIsSelected;
                checkBoxC.IsChecked            = toolSettings.CIsSelected;
                checkBoxD.IsChecked            = toolSettings.DIsSelected;
                checkBoxPrefix.IsChecked       = toolSettings.PrefixSelected;
                textBoxPrefix.Text             = toolSettings.PrefixText;
                checkBoxIntermediate.IsChecked = toolSettings.IntermediateSelected;

                for (int i = 0; i < comboBoxIntermediate.Items.Count; i++)
                {
                    string itemText = comboBoxIntermediate.Items[i].ToString();
                    if (itemText == toolSettings.IntermediateText)
                    {
                        comboBoxIntermediate.SelectedIndex = i;
                    }
                }

                checkBoxElevation.IsChecked = toolSettings.ElevationSelected;
                checkBoxABCD.IsChecked      = toolSettings.ABCDSelected;
                checkBoxSuffix.IsChecked    = toolSettings.SuffixSelected;

                for (int i = 0; i < comboBoxSuffix.Items.Count; i++)
                {
                    string itemText = comboBoxSuffix.Items[i].ToString();
                    if (itemText == toolSettings.SuffixText)
                    {
                        comboBoxSuffix.SelectedIndex = i;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to get Elevation Creator settings.\n" + ex.Message, "Elevation Creator: GetToolSettings", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }