简体   繁体   中英

TTS WP8 Pivot Pages

I am designing a settings page for my application and I'm using pivot pages, I cant seem to figure out, how to get the text to speech to work once the user goes to the next pivot page.

public partial class Settings : PhoneApplicationPage
{
    IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;

    List<Theme1> themesettings = new List<Theme1>();
    List<Theme1> font = new List<Theme1>();
    List<Theme1> fontsize = new List<Theme1>();
    public Settings()
    {
        InitializeComponent();

        themesettings.Add(new Theme1() { ThemeColour = "White", ThemeFontSize = "40" });
        themesettings.Add(new Theme1() { ThemeColour = "Yellow", ThemeFontSize = "40"});
        themesettings.Add(new Theme1() { ThemeColour = "Blue", ThemeFontSize = "40" });
        themesettings.Add(new Theme1() { ThemeColour = "Black", ThemeFontSize = "40" });

        LLsThemeList.ItemsSource = themesettings;

        font.Add(new Theme1() { ThemeText = "White", ThemeFontSize = "40" });
        font.Add(new Theme1() { ThemeText = "Yellow", ThemeFontSize = "40" });
        font.Add(new Theme1() { ThemeText = "Black", ThemeFontSize = "40" });

        LLsFontList.ItemsSource = font;

        fontsize.Add(new Theme1() { ThemeText = "White", ThemeFontSize = "25" });
        fontsize.Add(new Theme1() { ThemeText = "White", ThemeFontSize = "35" });
        fontsize.Add(new Theme1() { ThemeText = "White", ThemeFontSize = "50" });

        LLsTextSizeList.ItemsSource = fontsize;
    }

    private async void SayWords(string words)
    {
        SpeechSynthesizer synth = new SpeechSynthesizer();

        await synth.SpeakTextAsync(words);
    }

    private void ButtonSettings_Click(object sender, RoutedEventArgs e)
    {
        NavigationService.Navigate(new Uri("/Instructions.xaml", UriKind.Relative));
    }

    private void LLsFontList_Tap(object sender, System.Windows.Input.GestureEventArgs e)
    {
        if (LLsFontList != null && LLsFontList.SelectedItem != null)
        {
            var selectedItem = LLsFontList.SelectedItem as Theme1;

            settings["ForeColour"] = selectedItem.ThemeText;

            SayWords("You have chosen Font Colour" + selectedItem.ThemeText + "\r\n");
        }
    }

    private void LLsTextSizeList_Tap(object sender, System.Windows.Input.GestureEventArgs e)
    {
        if (LLsTextSizeList != null && LLsTextSizeList.SelectedItem != null)
        {
            var selectedItem = LLsTextSizeList.SelectedItem as Theme1;
            SayWords("You have chosen Font size " + selectedItem.ThemeFontSize);

            settings["FontSize"] = selectedItem.ThemeFontSize;
        }
    }

    private void LLsThemeList_Tap(object sender, System.Windows.Input.GestureEventArgs e)
    {
        if (LLsThemeList != null && LLsThemeList.SelectedItem != null)
        {
            var selectedItem = LLsThemeList.SelectedItem as Theme1;
            SayWords("You have chosen Theme Colour " + selectedItem.ThemeColour);

            settings["BackColour"] = selectedItem.ThemeColour;
        }
    }

    private void Confirm_Click(object sender, RoutedEventArgs e)
    {
        NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
        settings.Save();
    }
}

here is my code so far and I can get the TTS to work by calling out the certain settings the user has selected but I cant seem to figure out how to get the TTS to work when they change to the next pivot page.

Try implement Pivot.SelectionChanget event

Xaml

<phone:Pivot Title="MY APPLICATION" SelectionChanged="Pivot_SelectionChanged" >        
    <phone:PivotItem Header="first">
    ...
    </phone:PivotItem>        
    <phone:PivotItem Header="second">
    ...
    </phone:PivotItem>
</phone:Pivot>

Code

private void Pivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    Pivot pivot = sender as Pivot;
    PivotItem selectedPivotItem = pivot.SelectedItem as PivotItem;
    string pivotName = selectedPivotItem.Header.ToString();
    SayWords(pivotName);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM