private void prepareCommand() { readTextRoutedCommand = new RoutedCommand("ReadTextRoutedCommand", typeof(MemorizeGrid)); CommandManager.RegisterClassCommandBinding(typeof(MemorizeGrid), new CommandBinding(readTextRoutedCommand, (s, e) => { if (e.Source is Button) { Button btn = e.Source as Button; if (btn.DataContext is MemorizeReadText) { SpeechHelper.Instance.CancelSpeakAsync(); MemorizeReadText readText = this.openedButton1.DataContext as MemorizeReadText; SpeechHelper.Instance.SpeakAsync(readText.Text, -4); } } })); }
private void setButtonStyle(Button btn) { MemorizeObject obj = btn.Tag as MemorizeObject; if (btn.Tag is MemorizeReadText) { btn.Style = this.AudioButtonStyle; MemorizeReadText memorizeReadText = btn.Tag as MemorizeReadText; SpeechHelper.Instance.SpeakAsync(memorizeReadText.Text, -3); } else if (btn.Tag is MemorizeText) { btn.Style = this.TextButtonStyle; } else if (btn.Tag is MemorizeImage) { MemorizeImage memorizeImage = btn.Tag as MemorizeImage; if (memorizeImage.Count >= 0) { int imageWidth = (int)(this.itemWidth / 4f); memorizeImage.GenerateItems(0, (this.itemHeight - this.itemWidth) / 2, this.itemWidth - imageWidth, this.itemWidth - imageWidth, imageWidth); btn.Style = this.ImageButtonStyle; } else { btn.Style = this.ImageButtonNoRepeatStyle; } } else if (btn.Tag is MemorizeMusic) { btn.Style = this.AudioButtonStyle; MemorizeMusic memorizeMusic = btn.Tag as MemorizeMusic; this.audioItemMediaPlayer.Stop(); this.audioItemMediaPlayer.Close(); this.audioItemMediaPlayer.Open(new Uri(memorizeMusic.Url, UriKind.Absolute)); this.audioItemMediaPlayer.Play(); } }