2つの異なるスタックパネルに2つのフロードキュメントが並べてあります。私は特定のテキストのために両方のドキュメントを同時に検索する方法が必要です。私がテキストボックスに "car"とタイプする場合、フロードキュメントリーダーは両方とも必要であり、 "car"の次のインスタンスがあればそれを検索してスクロールする必要があります。これを達成する方法はありますか? FlowDocumentはFlowDocumentReaderの内部にあります。同時に2つのFlowDocumentsを検索する方法はありますか?
0
A
答えて
3
ここでは、指定した2つのFlowDocumentReadersを持つ基本的なWPF XAMLレイアウトがあります。私は、検索テキストボックスを持っており、いつでも検索テキストの変更の後ろにコードを実行するつもりです:MainWindow.xaml.csファイルで
<Window x:Class="WpfFlowTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfFlowTest"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<DockPanel>
<!-- Search Box -->
<TextBox Name="SearchTextBox" DockPanel.Dock="Top" TextChanged="TextBox_TextChanged"/>
<!-- 2 Flow Readers -->
<UniformGrid Columns="2">
<FlowDocumentReader Name="FlowReader1">
<FlowDocument>
<Paragraph>
Here is some text in panel number 1
</Paragraph>
</FlowDocument>
</FlowDocumentReader>
<FlowDocumentReader Name="FlowReader2">
<FlowDocument>
<Paragraph>
Here is some more text in panel number 2
</Paragraph>
</FlowDocument>
</FlowDocumentReader>
</UniformGrid>
</DockPanel>
</Window>
私は、テキストが何一致するフローの文書をハイライト表示します。このコードを持っています入力された:
private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
{
var searchText = SearchTextBox.Text;
DoSearch(FlowReader1, searchText);
DoSearch(FlowReader2, searchText);
}
private void DoSearch(FlowDocumentReader reader, string search)
{
var doc = reader.Document;
var text = doc.ContentStart;
var docRange = new TextRange(doc.ContentStart, doc.ContentEnd);
docRange.ClearAllProperties();
while (true)
{
var next = text.GetNextContextPosition(LogicalDirection.Forward);
if (next == null)
{
break;
}
var txt = new TextRange(text, next);
int indx = txt.Text.IndexOf(search);
if (indx > 0)
{
var sta = text.GetPositionAtOffset(indx);
var end = text.GetPositionAtOffset(indx + search.Length);
var textR = new TextRange(sta, end);
// Make it yellow
textR.ApplyPropertyValue(TextElement.BackgroundProperty, new SolidColorBrush(Colors.Yellow));
}
text = next;
}
}
0
私はスクロールしたい人のための私の若干の修正を掲載しました。
private void TextBox_TextChanged(object sender, EventArgs e)
{
var searchText = SearchTextBox.Text;
if (searchText != null || searchText != "")
{
var FlowReader1 = (FlowDocumentReader)diffResults.Children[0];
var FlowReader2 = (FlowDocumentReader)oldResults.Children[0];
DoSearch(FlowReader1, searchText);
DoSearch(FlowReader2, searchText);
}
}
private void DoSearch(FlowDocumentReader reader, string search)
{
bool toScroll = true;
var doc = reader.Document;
var text = doc.ContentStart;
var docRange = new TextRange(doc.ContentStart, doc.ContentEnd);
docRange.ClearAllProperties();
while (true)
{
var next = text.GetNextContextPosition(LogicalDirection.Forward);
if (next == null)
{
break;
}
var txt = new TextRange(text, next);
int indx = txt.Text.IndexOf(search);
if (indx >= 0)
{
var sta = text.GetPositionAtOffset(indx);
var end = text.GetPositionAtOffset(indx + search.Length);
if (end == null)
{
end = text.GetPositionAtOffset(indx + 1);
}
var textR = new TextRange(sta, end);
if (toScroll && text.Paragraph != null)
{
text.Paragraph.BringIntoView();
toScroll = false;
}
// Make it yellow
textR.ApplyPropertyValue(TextElement.BackgroundProperty, new SolidColorBrush(Colors.Yellow));
}
text = next;
}
関連する問題
- 1. if-else文で同時に2つのテキストボックスを単純に検証する方法はありますか? (c#)
- 2. 2つのUIViewで同時にUIlabelテキストを同時に更新する方法はありますか?
- 3. 同時に2つのテキストボックスを検証する方法は?
- 4. 検索時に2つの結果を許可する方法
- 5. 同時に2つのCSSプロパティに同じ値を割り当てる方法はありますか?
- 6. 2つ以上のtmux(またはtmuxinator)セッションを同時に開始する方法はありますか?
- 7. 検索結果を検索する方法はありますか?
- 8. Androidに2つのマイクを同時に録音する方法はありますか?
- 9. TimerService:同時に2つのタイマーインスタンスを実行しないようにする方法はありますか?
- 10. npmでスコープパッケージを検索する方法はありますか?
- 11. これらの2つのIDを同時にonclickで表示する方法はありますか?
- 12. Androidエミュレータ、2つのアプリケーションを同時に制御する方法はありますか?
- 13. pyqtで同時に2つのスレッドを実行する方法はありますか?
- 14. 同時に2つのBoostプリプロセッサシーケンスを反復処理する方法はありますか?
- 15. 複数のFlowDocumentsを1つのFlowDocumentに連結する方法
- 16. 2つのjQueryアニメーションを(適切に)同時に実行させる方法はありますか?
- 17. 2つのリストボックスから同時に選択する方法は?
- 18. MYSQLで複数の列のデータのスジを同時に検出/検出する方法はありますか?
- 19. 2つの検索テキストパラメータを使用してpostgres検索する方法、検索フィルタテキスト1 &&検索フィルタテキスト2
- 20. 2つの結果で同時に2つの検証を行う方法
- 21. javacriptのページ検索でfindを検出する方法はありますか?
- 22. 2つのジョインテーブルを同じ2つのクラスをレールアプリケーションに関連付ける方法はありますか?
- 23. 検索結果の値をクリック時に入力要素に割り当てる方法はありますか?
- 24. .NETストリームをバッファなしで同時に2つのストリームに書き込む方法はありますか?
- 25. 同じページで2つのmysqlクエリを検索しますか?
- 26. PHPと同時に2つの内部htmlファイルを検索する
- 27. xcodeで同時に2つのアプリケーションをデバッグする方法は?
- 28. 2つのモデルで同時にレコードをサブミットする方法は?
- 29. 同時に2つのjquery関数があります
- 30. Qt Creator 2.3で2つのソースファイルを同時に開く方法はありますか?
これはかなり良い解決策です。 – jailorboy
文書を強調表示されたテキストにスクロールする方法はありますか? – jailorboy
私の知る限りでは、文書を強調表示されたテキストにスクロールする組み込みの方法はありませんが、 'LineHeight'、' PagePadding'、その他の余白やマージン(スペーシング段落の間に)。 – Meloviz