繁体   English   中英

TTS WP8枢轴页面

[英]TTS WP8 Pivot Pages

我正在为我的应用程序设计一个设置页面,并且正在使用数据透视页面,我似乎无法弄清楚,一旦用户转到下一个数据透视页面,如何使文本转换为语音。

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();
    }
}

这是到目前为止的代码,我可以通过调用用户选择的某些设置来使TTS正常工作,但是当它们切换到下一个枢纽页面时,我似乎无法弄清楚如何使TTS正常工作。

尝试实现Pivot.SelectionChanget事件

XAML

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

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);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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