Save addin settings

Nov 23, 2010 at 6:22 PM

Hi,

I am loading a UIElement from an addin which is used as the AddIns settings interface:

    private void Settings_Click(object sender, RoutedEventArgs e)
    {
      SettingsWindow sw = new SettingsWindow();
      
      FrameworkElement settingsUI = null;
      this.Dispatcher.Invoke((Action)delegate() { settingsUI = SelectedAddIn.PopulateSettingsIU(); });


      sw.rootGrid.Children.Clear();
      if (settingsUI != null)
        sw.rootGrid.Children.Add(settingsUI);
      sw.ShowDialog();
      
      
    }

This loads a UIElement that consists of the following:

<UserControl x:Class="PakBusIPAddin.PakBusIPSettingsDialog"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:settings="clr-namespace:TestAddin.Properties"
  Height="400" Width="400" Unloaded="UserControl_Unloaded">
  <StackPanel>
    <Label Content="This is a test dialog for the PakBus IP Settings"/>
    <GroupBox Header="NL100 Settings">

      <Grid>
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="*"/>
          <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
          <RowDefinition Height="*" />
          <RowDefinition Height="*" />
          <RowDefinition Height="*" />
          <RowDefinition Height="*" />
          <RowDefinition Height="*" />
          <RowDefinition Height="*" />
          <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <Label Grid.Row="1" Content="IP Address"/>
        <TextBox Grid.Row="1" Grid.Column="1" Name="txtIPAddress" Text="{Binding Source={x:Static settings:Settings.Default},Path=PakBusIPAddress, Mode=TwoWay}"/>
        <Label Grid.Row="2" Content="Port"/>
        <TextBox Grid.Row="2" Grid.Column="1" Name="txtPort" Text="{Binding Source={x:Static settings:Settings.Default},Path=PakBusPort, Mode=TwoWay}"/>
        <Label Grid.Row="3" Content="PakBus Address"/>
        <TextBox Grid.Row="3" Grid.Column="1" Name="txtPakBusNeighbour" Text="{Binding Source={x:Static settings:Settings.Default},Path=PakBusNeighbourAddress, Mode=TwoWay}"/>
      </Grid>
    </GroupBox>
    <Label Content="Application ID" />
    <TextBox Grid.Row="3" Grid.Column="1" Name="txtPakBusApplicationID" Text="{Binding Source={x:Static settings:Settings.Default},Path=PakBusApplicationID, Mode=TwoWay}"/>

  </StackPanel>
</UserControl>
namespace PakBusIPAddin
{
  /// <summary>
  /// Interaction logic for PakBusIPSettingsDialog.xaml
  /// </summary>
  public partial class PakBusIPSettingsDialog : UserControl
  {
    public PakBusIPSettingsDialog()
    {
      InitializeComponent();
    }

    private void UserControl_Unloaded(object sender, RoutedEventArgs e)
    {
      //this doesn't save the settings???
      TestAddin.Properties.Settings.Default.Save();
    }
  }
}

 

that is mean't to store its settings back to the addins assembly, however it doesn't.

I have also tried adding

Properties.

 

Settings.Default.Save();

to the actual settings window within the main application, but this also doesn't work...

can anyone point me in the right direction?