-1
我發佈了這條代碼,以便代碼對任何人都有用。將文本添加到TextBlock中,每次只能輸入一個字符
基於Noctis的建議稍微縮減了代碼。
StringBuilder DescriptionText = new StringBuilder();
async void RunDescription(StringBuilder description)
{
DescriptionText = description;
await Task.Delay(1000); // Short delay before the text starts printing so the window has time to load
new Thread(AddTextToTextBlock).Start();
}
void TextBlockDispatcher(string text)
{
TextBlock1.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => TextBlock1.Inlines.Add(text)));
}
void AddTextToTextBlock()
{
foreach (char c in DescriptionText.ToString())
{
Thread.Sleep(30);
TextBlockDispatcher(c.ToString());
}
}
您希望某人查看並提出建議的工作代碼屬於codereview.stackexchange.com。即使在那裏,你也需要提供一個很好的[mcve],清楚地說明你想要評論的方面。堆棧溢出是針對特定的,實用的_problems_和代碼。 –
我投票結束這個問題作爲題外話,因爲它屬於codereview.stackexchange.com – Jeff
@PeterDuniho謝謝,我會在將來牢記這一點。 – Cusha