1

次のコード スニペットは、システム例外をスローします。

TextBlock selectionText = new TextBlock();                        
                    selectionText.IsTextSelectionEnabled = true;                        
                    selectionText.Text = "Hello world";                        
                    selectionText.Foreground = new SolidColorBrush(global::Windows.UI.Color.FromArgb(255, 255, 0, 0));
                    selectionText.SelectAll();

私のコードで何が間違っていますか?

前もって感謝します

4

2 に答える 2

2

selectionText呼び出す前に が表示されていることを確認する必要がありますSelectAll()。つまり、現在のページ内のパネルに追加する必要があります。

TextBlock selectionText = new TextBlock();
selectionText.IsTextSelectionEnabled = true;
selectionText.Text = "Hello world";
selectionText.Foreground = new SolidColorBrush(global::Windows.UI.Color.FromArgb(255, 255, 0, 0));
MainPanel.Children.Add(selectionText);
Dispatcher.RunAsync(CoreDispatcherPriority.Normal, selectionText.SelectAll);

2 つの変更点に注意してください。

  • MainPanel.Children.Add()whereの呼び出しMainPanelは、ページ上のパネル コントロールの名前です。
  • selectionText.SelectAll()呼び出しが実行される前に実際にパネルに追加されてDispatcherいることを確認するために経由で呼び出されます。selectionText
于 2013-02-28T05:49:55.807 に答える
0

私の推測では、前景の色です

Color.FromArgb(255, 255, 0, 0)

最初の数字は、透明度を意味する「アルファ」のレベルを決定します。Windows RT では対応できない場合があります。

代わりにこれを試してください

Color.FromArgb(0, 255, 0, 0)
于 2013-02-28T05:55:41.180 に答える