Why when saving to Settings radio button states it keep loading the first radio button state and not the last radio button state changed? how to save it to the settings ?

Sani Berko 41 Reputation points
2022-08-11T21:07:05.25+00:00

When loading :

private void MainWindow_Loaded(object sender, RoutedEventArgs e)  
        {  
radioButtonWatchDirectory.IsChecked = Properties.Settings.Default.RadioButtonWatchDirectory;  
radioButtonWatchFile.IsChecked = Properties.Settings.Default.RadioButtonWatchFile;  
checkBoxIncludeSubdirectories.IsChecked = Properties.Settings.Default.IncludeSubDirectories;  
textBoxFileDirectory.Text = Properties.Settings.Default.BrowseFolderDialog;  
        }  

When setting and saving :

private void radioButtonWatchFile_Checked(object sender, RoutedEventArgs e)  
        {  
            Properties.Settings.Default.RadioButtonWatchFile = (bool)radioButtonWatchFile.IsChecked;  
            Properties.Settings.Default.Save();  
        }  
  
      
  
private void radioButtonWatchDirectory_Checked(object sender, RoutedEventArgs e)  
    {  
        Properties.Settings.Default.RadioButtonWatchDirectory = (bool)radioButtonWatchDirectory.IsChecked;  
        Properties.Settings.Default.Save();  
    }  

When running the application once i checked true the Watch File radio button no matter if i check the Watch Directory radio button next time i will run the application the Watch File radio button will be checked. like it's not remembering changing it to the Watch Directory radio button.

The Include Subdirectories is working fine.

230540-watch1.jpg

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,710 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,648 questions
XAML
XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
790 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 114.7K Reputation points
    2022-08-12T08:09:25.893+00:00

    Try one of solutions:

    private void radioButtonWatchFile_Checked( object sender, RoutedEventArgs e )  
    {  
        Properties.Settings.Default.RadioButtonWatchFile = true;  
        Properties.Settings.Default.RadioButtonWatchDirectory = false;  
        Properties.Settings.Default.Save( );  
    }  
      
    private void radioButtonWatchDirectory_Checked( object sender, RoutedEventArgs e )  
    {  
        Properties.Settings.Default.RadioButtonWatchFile = false;  
        Properties.Settings.Default.RadioButtonWatchDirectory = true;  
        Properties.Settings.Default.Save( );  
    }  
    
    0 comments No comments

0 additional answers

Sort by: Most helpful