[英]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.