0
나는 WPF에 익숙하지 않다. 그래서 내 무지를 용서해 주길 바란다. 나는 약 30 분 동안이 이슈를 인터넷 검색하려하고 나의 시나리오에 맞는 간단한 해결책을 찾지 못하는 것 같다.코드에서 WPF RichTextBox를 효율적으로 적용하기
기본적으로 나는 서버에서 라인을 읽는 IRC 앱을 만들고, 나는 그 별명과 메시지를 읽었다. 그리고 같은 라인을 넣으십시오 :
<Nick> Message typed...
나는 굵은 글씨로 <Nick>
을 원합니다. 그리고 나중에 색깔에 아마. 또한 각 루프마다 몇 가지 예제를 살펴 보았습니다. 그러나 1000 + 라인이 있고 foreach 루프를 수행 할 때마다 누군가가 뭔가를 입력하면 비효율적이지 않습니까?
C# 프로그래밍 측면에서 최선의 방법과 가장 쉬운 방법을 알려주십시오.
private void OnChannelMessage(object sender, IrcEventArgs e)
{
if (!txtActivity.Dispatcher.CheckAccess())
{
txtActivity.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate()
{
txtActivity.AppendText(string.Format("<Bold><{0}:{1}></Bold> {2}\n", e.Data.Channel, e.Data.Nick, e.Data.Message));
//Paragraph p = new Paragraph();
//p.Inlines.Add(new Bold(new Run(string.Format("<{0}> ", e.Data.Nick))));
//p.Inlines.Add(new Run(string.Format("{0}\n", e.Data.Message)));
//txtActivity.Document.Blocks.Add(p); // problem adds a big space between lines.
}
));
}
}
XAML :
<Grid>
<RichTextBox Name="txtActivity" VerticalScrollBarVisibility="Auto" Margin="12,12,12,41" BorderThickness="2" FontFamily="Consolas">
<RichTextBox.Resources>
<Style TargetType="{x:Type Paragraph}">
<Setter Property="Margin" Value="0"/>
</Style>
</RichTextBox.Resources>
</RichTextBox>
<Button Content="Quit" Height="23" HorizontalAlignment="Left" Margin="628,371,0,0" Name="btnQuit" VerticalAlignment="Top" Width="50" Click="btnQuit_Click" />
</Grid>