Hello, I want to make a font change in FixedHtmlTextBlock. And I decided to create 2 different Data Template, one by default (with a font size of 20), and the other will be selected in the settings (with a size of 25). The problem is the following: when I save an enlarged font, when I switch to another page and back, the font remains enlarged, and when I close the application and I go again, the setting of the enlarged font is not saved.

Receiving settings:

public Section1Detail() { InitializeComponent(); // Размер текста if (IsolatedStorageSettings.ApplicationSettings.Contains("TextSize")) { Container.ItemTemplate = (DataTemplate)(IsolatedStorageSettings.ApplicationSettings["TextSize"]); } } 

Saving settings:

 Container.ItemTemplate = (DataTemplate)this.Resources["Large"]; IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings; if (!settings.Contains("TextSize")) { settings.Add("TextSize", Container.ItemTemplate); } else { settings.Remove("TextSize"); settings.Add("TextSize", Container.ItemTemplate); } settings.Save(); 

    1 answer 1

    In IsolatedStorageSettings you can only save objects of serializable types. DataTemplate not. Since you need to keep the size, the use of DataTemplate is also somewhat redundant. If I were you, I would save the size as a number in the settings.

    PS Yes, and when adding a setting, it is enough to write like this, all these checks and Remove not needed:

     settings["TextSize"] = textSize; 
    • rather than tell me how to change the font size in FixedHtmlTextBlock in the code. I have trouble because FixedHtmlTextBlock is in the DataTemplate, and the DataTemplate itself is in PhoneApplicationPage.Resources - Max Bazanov
    • @MaxBazanov apparently, is this some kind of custom control? I could be mistaken in details, but I would try this: 1) remove the DataTemplate from resources (it is not needed there now), 2) access the FontSize property from the control to save and set the text size. There will have to establish the interaction between the view model and the code behind. - andreycha