0
votes

I have a Windows Phone 8.1 app in which I have two pages. First is the MainPage.xaml in which I am using a longlistselector control to show a list. On the Settings.xaml page, I have a font size selection for the user using the Listpicker control.

The question is, once the user selects a new font size on the Settings page, I want to change the font in the longlistselector on MainPage. However, a longlistselector decaled on the MainPage.xaml is not available on the Settings page. (I am setting the itemssource of the longlistselector in the MainPage.cs file.)

How should I resolve this issue? Should I use a page event of MainPage.xaml and detect if a font size has been changed by the user? What is the standard way of tackling this problem?

XAML in Settings.xaml:

<TextBlock Text="Select Font" Margin="0,0,0,0"/>
            <toolkit:ListPicker Name="fontlistpicker" Tap="fonttapped" Margin="0,35,0,0" Grid.Row="0" SelectionChanged="fontlistpicker_SelectionChanged">
                <toolkit:ListPickerItem x:Name="Font1" Content="10"/>
                <toolkit:ListPickerItem x:Name="Font2" Content="20"/>
                <toolkit:ListPickerItem x:Name="Font3" Content="30"/>
                <toolkit:ListPickerItem x:Name="Font4" Content="40"/>
                <toolkit:ListPickerItem x:Name="Font5" Content="50"/>
            </toolkit:ListPicker>

XAML in MainPage.xaml:

<phone:LongListSelector Name="myList" >
<phone:LongListSelector.ListHeader>
     <TextBlock  Name ="dailyHeader" Margin="0,0,0,10" HorizontalAlignment="Center"/>
</phone:LongListSelector.ListHeader>
</phone:LongListSelector>
1
Can you tell if the solution provided has worked for you? If yes, please mark it as the correct answer.. :)Kasun Kodagoda

1 Answers

1
votes

When you navigate away from the Settings.xaml page you can use OnNavigatedFrom() method to save your settings to IsolatedStorageSettings. Then in the MainPage.xaml in code behind in the OnNavigatedTo() method you can load that settings Value from The IsolatedStorageSettings and set the font in your LongListSelector. That is the way to Do it. In your Settings page, Add the following code

protected override void OnNavigatedFrom(NavigationEventArgs e)
{
    base.OnNavigatedFrom(e);
    string key = "Font-Size";
    IsolatedStorageSettings.ApplicationSettings[key] = (fontlistpicker.SelectedItem as ListPickerItem).Content.ToString();
}

then in the MainPage.xaml.cs file Add the following

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    base.OnNavigatedTo(e);
    if (IsolatedStorageSettings.ApplicationSettings.Contains("Font-Size"))
    {
        string fontSize = IsolatedStorageSettings.ApplicationSettings["Font-Size"] as string;     

        // Code to set the Font size of your LongListSelector
    }
}