FatalExecutionEngineError in RichTextBox - wpf

Sometimes, just sometime, I get FatalExecutionEngineError while trying to get text position from mouse position in RichTextBox. And the second problem is I can't handle FatalExecutionEngineError and it crashes the app.
// e.MouseDevice.GetPosition(XAMLRichBox) is not null
var tp = myRichBox.GetPositionFromPoint(e.MouseDevice.GetPosition(XAMLRichBox), true);

I've encountered the similar problem when working with RichTextFormat and probably my experience may help you too.
I've encountered the abovementioned exception when user was calling Undo action in richtextedit control. The exception was thrown on undo if there are particular actions has been done previously that included the insert into CaretPosition the content of the separately created FlowDocument:
Document.ContentStart.InsertParagraphBreak();
RichTextBox.InsertDocument(Document, RichTextBox.CaretPosition);
My solution was to envelope the above action in BeginChange()/EndChange() (that was perfectly suited the requirements):
RichTextBox.BeginChange();
try
{
Document.ContentStart.InsertParagraphBreak();
RichTextBox.InsertDocument(Document, RichTextBox.CaretPosition);
}
finally
{
RichTextBox.EndChange();
}
I guess this might give you idea to solve your problem

Related

Umbraco cms AngularJS Regular Expression Keep appearing

Umbraco uses angularJS as based library and backoffice totally developed on it. The reason telling first is to tell that I have a field on which URL regular expression applied. If someone entered invalid url like below image
it shows error as need.
But if a user try to remove whole text by selecting it and removing at once. It still keep appearing the error like this
However, if a user erase text one by one like this
then the validation error removed and user need to click on button to see error again.
I would to know how screen 3 state can be achievable when user remove all text together? Its really annoying behavior for a user to remove text character one by one to refresh the state of the field. Screen 3 state should be applied on screen 2.
Can anybody tell me how it can fix or achievable? Right now, it seems like a default behavior.
Looking forward to hear from you guys. Suggestions will be much appreciatable.
Regards o
I've looked into this issue. This seems to be a product bug.
When you remove whole text at once, newValue is an empty string and the code responsible for resetting error messages doesn't run. If you have access to the umbraco code, you can easily fix it by removing highlighted check:

Reload Grid in ATK4

I'm trying to learn enough to create a website that lets people answer quiz questions using Agile Toolkit 4.2.
I have a page that displays one question and its answer choices from the 'sampleq' model. I want to make a button that displays the next record in the model.
I've tried a bunch of different ways to get the js()->reload() command to work properly, but I haven't been able to do it. I get AJAX "unexpected identifier" error. I've been through the related questions on this site and looked for documentation on the ATK site, but I haven't found an example that works for me.
Can anybody tell me how to get the button to properly reload the grid?
function init(){
parent::init();
$page=$this;
}
function page_qlisting() {
$qid=$this->recall('value',1);
echo $qid;
$NextB=$this->add('Button')->SetLabel('Next Question '.$qid);
$grid=$this->add('Grid');
$grid->setModel('sampleq',array('question','A1','A2','A3'));
$grid->dq->where('id=',$qid);
if($NextB->isClicked()){
//$this->memorize('value',$qid+1);
$grid->js()->reload();
}
}
function page_qentry() {
$this->api->auth->check();
$this->add('Html')->set('Welcome to the question entry page.<br>');
$this->add('CRUD')->setModel('sampleq');
}
}
Edit:
After reading Romans' answer, I first tried this:
$qid=$this->recall('value',1);
$grid=$this->add('Grid');
$grid->setModel('sampleq',array('id','question','A1','A2','A3'));
$grid->dq->where('id=',$qid);
$this->add('Button')->SetLabel('Next Question')->js('click', $this->memorize('value',$qid+1))->js('click', $grid->js()->reload());
That actually works - it displays only one record at a time, and it displays the next one when I click the button. Next I tried adding a "Previous" button like so:
$qid=$this->recall('value',1);
$grid=$this->add('Grid');
$grid->setModel('sampleq',array('id','question','A1','A2','A3'));
$grid->dq->where('id=',$qid);
$this->add('Button')->SetLabel('Previous Question')->js('click', $this->memorize('value',$qid-1))->js('click', $grid->js()->reload());
$this->add('Button')->SetLabel('Next Question ')->js('click', $this->memorize('value',$qid+1))->js('click', $grid->js()->reload());
This doesn't work, though. Both buttons are decrementing. I tried laying it out like your adjuster buttons example here. Here's what my increment button code looks like in that attempt:
$incr=$this->add('Button')->SetLabel('Next Question');
if($incr->isClicked()){
$this->memorize('value',$qid+1);
$grid->js()->reload();
}
In that case, I get "Error in AJAXec response: SyntaxError: Unexpected identifier" when I click the button.
Can you offer any advice on how to make increment and decrement work with a grid (or crud)? Why doesn't the adjuster example work when you try to refresh a grid instead of refreshing the button? Thanks for the previous answer, and thanks in advance for any additional guidance that you may have time to offer.
This should be it:
$this->add('Button')->js('click', $grid->js()->reload());
If you use CRUD you might want to reload CRUD instead.

Suppress navigation when setting HtmlPage.Window.CurrentBookmark property in Silverlight

I have a scenario where I need to change the HtmlPage.Window.CurrentBookmark property, but I want to do it without causing the Silverlight application to reload. Right now, I'm doing this, but it's causing the application to restart:
public void SetBookmark(string authenticationGroupTag, string ownerUserTag, string roomName)
{
string bookmark = GetBookmark(authenticationGroupTag, ownerUserTag, roomName);
HtmlPage.Window.CurrentBookmark = bookmark;
// HtmlPage.Window.Eval("window.location.hash='" + bookmark + "'");
}
That particular behavior -- restarting the application -- doesn't seem to be documented anywhere, so I wonder if I'm just doing it wrong. I've tried catching various navigation related events (either Page.OnNavigatedFrom or RootFrame.Navigating), but neither of those actually get fired: the app just unloads and then reloads.
So I guess I have two parts to my question: (1) Is this the expected behavior, or am I just doing something wrong? and (2) If it is the expected behavior, has anyone come up with a workaround for it? Is there a way to update the portion of the URL after the "#" without reloading the Silverlight application?
Turns out that this is just a variant of a problem that's been long noted, namely, that Internet Explorer refreshes the page when (a) the user has arrived at the current page after a redirect, and (b) you change the window.location.hash. In other words, this is an IE issue (still not fixed in IE9!), not a Silverlight problem. Everything behaves correctly with Firefox and Chrome. (See javascript location.hash refreshing in IE and Response.Redirect with a fragment identifier causes unexpected refresh when later using location.hash for more details, and some suggested workarounds.)

How to free WPF resources after they are no longer being used

I use a default image as a user avatar the first time my application is loaded. After that, the user can change their avatar. The problem is that after using a new avatar, the user cannot delete the old avatar. They get the error message: "file access denied". That means my application is still using the old image somewhere, but I don't know where.
My question is: How do I free the WPF resource after using it? I have looked around with Google, but found nothing.
Please help me!
Thanks.
You usually have to call Dispose() on class instances after use to free resources. Even better is to use the using statement that implicitly calls Dispose() like this:
using (FileStream fsSource = new FileStream(pathSource, FileMode.Open, FileAccess.Read))
{
// Load file content
}

Dynamic Hyperlink in Livecycle Form

I am trying to figure out how to make a hyperlink in a Livecycle Form which points to a URL which will change on different days that the form is rendered. For example on one day I might want the hyperlink to point to:
mywebsite/mypage?option=XXX
and on another day I want it to point to:
mywebsite/mypage?option=YYY
The XXX and YYY can be passed into the form's data pretty easily as XML, but I just don't know how to make it so that the hyperlink is changed to correspond to this.
Any suggestions?
This can be accomplished with JavaScript in LiveCycle Designer. The following script, placed on the Form's docReady event will let you dynamically change the URL of a text object.
form1::docReady - (JavaScript, client)
// If this code is running on the server, you don't want it to run any code
// that might force a relayout, or you could get stuck in an infinite loop
if (xfa.host.name != "XFAPresentationAgent") {
// You would load the URL that you want into this variable, based on
// whatever XML data is being passed into your form
var sURL = "www.stackoverflow.com"; // mywebsite/mypage?option=xxx
// URLs are encoded in XHTML. In order to change the URL, you need
// to create the right XHTML string and push it into the Text object's
// <value> node. This is a super simple XHTML shell for this purpose.
// You could add all sorts of markup to make your hyperlink look pretty
var sRichText = "<body><p>Foo</p></body>";
// Assuming you have a text object called "Text1" on the form, this
// call will push the rich text into the node. Note that this call
// will force a re-layout of the form
this.resolveNode("Text1").value.exData.loadXML(sRichText, false, true);
}
There are a couple of caveats: URLs in Acrobat are only supported in Acrobat 9.0 and later. So if someone using an older version of Acrobat opens your form, the URLs won't work.
Also, as you can see from the "if (xfa.host.name !=...)" line, this code won't run properly if the form is being generated on the server, because forcing a re-layout of a form during docReady can cause problems on certain older versions of the LiveCycle server. If you do need to run this script on the server, you should probably pick a different event then form::docReady.
I a number of complaints from users in WorkSpace that clicking links opened them in the same tab so they lost their WorkSpace form, and there's no option to change that in Designer 11. I think the solution I came up with for that would work for you too.
I made buttons with no border and no background, and in their click event have this line (in Javascript, run at client)
app.launchURL("http:/stackoverflow.com/", true);
It would be easy to add some logic to choose the right URL based on the day and it doesn't cause any form re-rendering.
In some spots where the hyperlink is in line with other text, I leave the text of the link blue and underlined but with no hyperlink, and just place the button (no background, no border, no caption) over it. Does require positioned and not flowed subforms for that to work, so depending on your layout it could get a little clunky.
Wow, just realized I am super late to the party. Well, for anyone using ES4 facing a similar problem . . .
Ended up using a 3rd party component to manipulate the PDF's hyperlinks...wish there was a better solution as this one costs about $1000.

Resources