Click here to Skip to main content
15,889,281 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: Xaml on the Web Pin
Mark Salsbery2-Feb-09 7:16
Mark Salsbery2-Feb-09 7:16 
GeneralRe: Xaml on the Web Pin
Jammer2-Feb-09 7:22
Jammer2-Feb-09 7:22 
GeneralRe: Xaml on the Web Pin
Pete O'Hanlon2-Feb-09 8:32
mvePete O'Hanlon2-Feb-09 8:32 
QuestionWPF ListView/ItemsControl Drag Drop Adorner Pin
snblackout29-Jan-09 18:40
snblackout29-Jan-09 18:40 
AnswerRe: WPF ListView/ItemsControl Drag Drop Adorner Pin
Pete O'Hanlon30-Jan-09 2:27
mvePete O'Hanlon30-Jan-09 2:27 
GeneralRe: WPF ListView/ItemsControl Drag Drop Adorner Pin
snblackout30-Jan-09 4:42
snblackout30-Jan-09 4:42 
GeneralRe: WPF ListView/ItemsControl Drag Drop Adorner Pin
snblackout30-Jan-09 5:33
snblackout30-Jan-09 5:33 
QuestionWPF RichTextBox is slow Pin
uncleashcan29-Jan-09 3:39
uncleashcan29-Jan-09 3:39 
I am trying to make a simple WPF app that takes a regex typed by the user into one RichTextBox, and highlights the matches in a second RichTextBox where the user can type in test data.

I will admit that this is my first foray into WPF, and theres probably something I am doing wrong. I am having two problems:

1. My highlights are not showing up in the right place.. they are off by a couple of characters early in the document, and towards the end they are nowhere close.

2. The performance I am seeing is abominable OMG | :OMG: To highlight about 200 three-character matches in a ~60kb document is taking over ten seconds. There are scenarios where I would need to highlight thousands of matches instead.. I can't fathom how long that would take. I am pretty certain the slow-down is in the action of highlighting, not processing the regex itself.

Just pasting the plain text into the RichTextBox in the first place (where it isnt executing any of my code) takes at least three seconds.

This is a rewrite of a windows forms app that I made a couple of years ago, and I managed to skirt around some of the RichTextBox performance issues there by using Suspend/ResumeLayout() but there doesn't appear to be an analogous tactic in WPF..

I should probably also note that no exceptions are actually being thrown. This was my first guess for the slow-down issue since exceptions take a while to churn out.. but the catch(...) in my code isn't being hit...

My machine is a Pentium 4 2.2ghz running Windows XP SP2. Here is the meat of my code.. what am I doing wrong?

void HighlightRegexMatches()
{
    if (!pHighlighting)
    {
        pHighlighting = true;

        Regex r = null;

        string p = new TextRange(
            rtbPattern.Document.ContentStart,
            rtbPattern.Document.ContentEnd
            ).Text.Replace("\r\n", "");

        try
        {
            r = new Regex(p);
        }
        catch (Exception ex)
        {
            // User typed an invalid regex, so cancel.

            pHighlighting = false;
        }

        if (r == null) return;

        try
        {
            string s = new TextRange(
                rtbTestData.Document.ContentStart,
                rtbTestData.Document.ContentEnd
                ).Text;

            MatchCollection c = r.Matches(s);

            FlowDocument d = rtbTestData.Document;

            TextRange allText = new TextRange(d.ContentStart, d.ContentEnd);

            allText.ApplyPropertyValue(TextElement.BackgroundProperty, Brushes.Transparent);

            int count = 0;

            foreach (Match m in c)
            {
                TextPointer start = d.ContentStart.GetPositionAtOffset(m.Index);

                TextPointer end = d.ContentStart.GetPositionAtOffset(m.Index + m.Length);

                TextRange t = new TextRange(start, end);

                t.ApplyPropertyValue(TextElement.BackgroundProperty, Brushes.HotPink);

                count++;
            }
        }
        catch (Exception ex)
        {
        }
        finally
        {
            pHighlighting = false;
        }
    }
}

GeneralRe: WPF RichTextBox is slow Pin
ejhuntington30-Jan-09 7:18
ejhuntington30-Jan-09 7:18 
QuestionDeep Zoom - Generate on Demand/Dynamically Pin
Dominic Pettifer28-Jan-09 14:46
Dominic Pettifer28-Jan-09 14:46 
AnswerRe: Deep Zoom - Generate on Demand/Dynamically Pin
ColinM12328-Jan-09 16:59
ColinM12328-Jan-09 16:59 
AnswerRe: Deep Zoom - Generate on Demand/Dynamically Pin
Mark Salsbery29-Jan-09 5:39
Mark Salsbery29-Jan-09 5:39 
QuestionAdding dynamically new lines and columns to a grid ? Pin
WolveFred228-Jan-09 4:20
WolveFred228-Jan-09 4:20 
AnswerRe: Adding dynamically new lines and columns to a grid ? Pin
ColinM12328-Jan-09 13:45
ColinM12328-Jan-09 13:45 
GeneralRe: Adding dynamically new lines and columns to a grid ? Pin
WolveFred229-Jan-09 2:41
WolveFred229-Jan-09 2:41 
GeneralRe: Adding dynamically new lines and columns to a grid ? [modified] Pin
Mark Salsbery29-Jan-09 5:46
Mark Salsbery29-Jan-09 5:46 
GeneralRe: Adding dynamically new lines and columns to a grid ? Pin
WolveFred229-Jan-09 7:37
WolveFred229-Jan-09 7:37 
GeneralRe: Adding dynamically new lines and columns to a grid ? Pin
Mark Salsbery29-Jan-09 7:52
Mark Salsbery29-Jan-09 7:52 
GeneralRe: Adding dynamically new lines and columns to a grid ? Pin
WolveFred229-Jan-09 8:04
WolveFred229-Jan-09 8:04 
GeneralRe: Adding dynamically new lines and columns to a grid ? Pin
Mark Salsbery29-Jan-09 9:15
Mark Salsbery29-Jan-09 9:15 
GeneralRe: Adding dynamically new lines and columns to a grid ? [modified] Pin
WolveFred22-Feb-09 4:37
WolveFred22-Feb-09 4:37 
GeneralRe: Adding dynamically new lines and columns to a grid ? Pin
Mark Salsbery2-Feb-09 5:55
Mark Salsbery2-Feb-09 5:55 
GeneralRe: Adding dynamically new lines and columns to a grid ? Pin
WolveFred23-Feb-09 3:31
WolveFred23-Feb-09 3:31 
QuestionFit to Screen in WPF [modified] Pin
AnkitSingh28-Jan-09 4:00
AnkitSingh28-Jan-09 4:00 
AnswerRe: Fit to Screen in WPF Pin
BlitzPackage28-Jan-09 13:50
BlitzPackage28-Jan-09 13:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.