print wpf window after it has been totally rendered which event? - c#

how to a print wpf window after it has been totally rendered which event?
i have tried using loaded but some of the elements have not finished rendered yet
thanks

Read this article it shows you that there currently is no official way of getting notified of the end of the rendering but instead shows you a trick that you could use.

I don't haev a proper solution for you, but you can make the following hack in the loaded event:
Dispatcher.BeginInvoke(new Action(delegate {
// here you are pretty shure that all rendering is done
// Put in your code here
}), System.Windows.Threading.DispatcherPriority.ContextIdle, null);
Probably it will also work with DispatcherPriority.Background, check it out.

Related

How do I avoid having my Rich Text Box, "scroll bar," freeze up?

My issue is in the .NET framework using C# to create a simple form application that contains a rich text box (RTB) control.
Briefly the issue I am experiencing is that when trying to clear the contents (.Text) of the RTB, the scroll bar doesn't go away. I would like to know if there is anything inherently wrong with the way I am using the RTB. I apologize, but the site will not allow me to post images yet. So if there is a misunderstanding regarding what "doesn't go away" means, please ask!
So first, I write data to the box using the following code snippet:
// append the new message
this.rtb_receive_0.Text += message;
this.rtb_receive_0.SelectionStart = this.rtb_receive_0.Text.Length;
this.rtb_receive_0.ScrollToCaret();
Later on, I clear the RTB contents (RTB.Text) with the following code:
this.rtb_receive_0.Text = String.Empty;
this.rtb_receive_0.Refresh();
In the above code I have attempted to fix my problem with the, "Refresh," method. However it does not seem to be doing the job.
When I clear the RTB contents, the scroll bar does not go away... I noticed that if I grab another window and drag it over the top of the application, that the frozen scroll bar disappears. Also, I can minimize the application, then maximize it again and the bar will disappear. There has to be a way to prevent this frozen scroll bar from happening in the first place though.
Per the answer, here was the fix to stop the bar from freezing up:
this.rtb_receive_0.Text = String.Empty;
this.rtb_receive_0.Clear();
this.rtb_receive_0.ScrollBars = RichTextBoxScrollBars.None;
this.rtb_receive_0.ScrollBars = RichTextBoxScrollBars.Vertical;
this.rtb_receive_0.Refresh();
Have you tried simply just programatically setting the Scrollbars property on the RTB?
myRichTextBox.ScrollBars = RichTextBoxScrollBars.None;
Edit: I think I misinterpreted what you needed. Searching around, I found this similar post on another forum: http://www.vbforums.com/showthread.php?793671-RESOLVED-RichTextBox-Visual-Bug
This user is setting the value of an RTB based on a selection in a list view. When a new value is set and does not require a scrollbar it doesn't re-draw and still shows the bar.
It seems like adding myRichTextBox.Clear(); myRichTextBox.Refresh(); should help. In this case that user is also programatically setting the ScrollBars property as well.
Also, are you able to determine how many lines of text can fit in the RichTextBox before a scrollbar is needed? I suppose that might vary based on system settings on the machine, but you might just be able to programatically check myrtb.Scrollbars = (myrtb.Lines.Length > X) ? Vertical : None; (excuse the psuedo code syntax)
What helped for me was just calling the refresh() method twice. Very ugly, but it does the job.
Hmm, after more thorough testing this ugly fix proved to be not so much of a fix afterall. It helps, but still some glitches.
refresh();
update();
seems like a better solution.
I was having this same problem. I solved it by calling the Invalidate() method which forces the control to repaint.
Me.RichTextBox.Clear()
'Call Invalidate in order to force the RichTextBox to repaint. I do this so that any
'Visible Scroll bars are removed after clearing the Text
Me.RichTextBox.Invalidate()
I tried with Refresh(); Update(); Invalidate();,but it didn't worked for me.
I solved this problem using following three lines :-
RitchTextBox.Clear(); //Clearing text in RichTextBox
RitchTextBox.ScrollBars = RichTextBoxScrollBars.None; //Remove scroll
RitchTextBox.ScrollBars = RichTextBoxScrollBars.Vertical; //Again add scroll
Try those above three lines. It will work 100%.

Custom dialog box in wpf issue

I'm calling my custom dialog window with this code:
GUI.SLDialog sd = new GUI.SLDialog();
if (sd.ShowDialog() == false)
{
return;
}
But sd.ShowDialog() always returns nothing (i think), because the function breaks, but the waypoint at return; isn't reached.
Dialog is automaticly closing when I add to button:
this.DialogResult = false;//or true
Anybody know what am I doing wrong?
Thanks in advance for your help.C.H.
#edit
This is my SLDialog:
xaml: http://wklej.org/hash/9fb67fb0c7c/
cs: http://wklej.org/hash/16e3ccc6c0d/
I don't think I can tell you much here unless you post the code for the dialog but I do have a suggestion in the mean time.
Since you're already unhappy with the standard dialog boxes and customization is clearly an option why not move towards what people are coming to expect? Instead of your standard dialog why not just create a user control that lays over the rest of your UI and blurs everything out from the background? Much like a jquery dialog box you might see on a web page.
Modality is easier to control since it's just a matter of covering your entire app window with a translucent rectangle and then make the dialog window appear however you want.
Just a suggestion.

gui not updating

I ran into the following problem with my kiosk application:
I have a window with some thumbnails. When the user clicks on a thumbnail, another window (docview) with info is displayed and in the center a document is shown..
I would like to have the docview visible instantly and then start loading the document (the document loading takes 1-3 secs)and add it to the interface afterwards.
At the moment when I click a thumb, the interfaces freezes for a second or two, and then the docview is visible with the document already..
This is what I do:
viewgrid.Children.Add(docView); // the main window uses this grid to display the windows
viewgrid.InvalidateVisual();
viewgrid.UpdateLayout(); // at this point I would like to have the docView visible
docView.showDocument(); //and afterwards, the loading of the document should start and be also visible eventually..
I tried using the LayoutUpdated event with no success..Also putting the showDocument in a separate thread didn't help either..I also read about Application.DoEvents(), but that's deprecated and seemed bad practice anyway..
How should I resolve this?
Thanks in advance!
You need to use a BackgroundWorker object to load the document. You said you tried threading, and it didn't work, but you need to get threading to work and I recommend you use a background worker.
http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker(v=vs.110).aspx
I am not sure what type of document you are loading, but I loaded a RichText file using Binding as described here:
http://www.rhyous.com/2011/08/01/loading-a-richtextbox-from-an-rtf-file-using-binding-or-a-richtextfile-control/
You would do the same thing only you load the document in a BackgroundWorker. Once the document is loaded, you update the bound property and the UI will update.
You can try to use async bindings. Or do it manually with another thread and Dispatcher. But it depends on that your ShowDocument is doing and that is slow.

Get "is ready" signal after rendering of WPF toolkit chart

I am using the charting stuff of the WPF toolkit.
After creating a chart I like to have a snaphshot of that chart, without visualizing that chart. My problem is that I don't know when the rendering process is done, so I can create a snapshot.
I tried listening to the "LayoutUpdated" event, but the chart is being updated very often.
Can anyone tell me how to find out if the chart is completely rendered?
You can use the Dispatcher in your code behind:
this.Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action(() =>
{
// code in here should be executed after chart has been rendered.
}
));
The Loaded event sounds like what you need.
MyChart.Loaded += (sender, e) =>
{
// chart has been loaded but not yet rendered
}
where "MyChart" is a the name you've given the chart in your XAML.
I'm not sure how well this works with frequent updates, but this link seems to indicate http://blogs.msdn.com/b/mikehillberg/archive/2006/09/19/loadedvsinitialized.aspx that this is what you're looking for.

Using F1 Help (CHM format) With WPF

I've been working on a WPF application for a while, and the time has come to attach the CHM format help document to it.
But alas! HelpProvider, the standard way to show CHM files in Winforms, has magically vanished and has no counterpart in WPF. I've been trying to use WindowsFormsHost to spawn a new control so I can actually display the help, but essentially it just grabs control of the entire UI.
A little more detail: I've got a menu item that I want to, when clicked, open up the CHM file.
First I set up the WindowsFormsHost...
host = new System.Windows.Forms.Integration.WindowsFormsHost();
helpForm = new System.Windows.Forms.Control();
host.Child = helpForm;
host.Visibility = System.Windows.Visibility.Hidden;
this.grid1.Children.Add(host);
hp = new System.Windows.Forms.HelpProvider();
hp.HelpNamespace = "Somehelpfile.chm";
hp.SetHelpNavigator(helpForm, System.Windows.Forms.HelpNavigator.TableOfContents);
And then I say, voila, reveal yourself.
private void Help_Click(object sender, RoutedEventArgs e)
{
host.Visibility = Visibility.Visible;
helpForm.Show();
hp.SetShowHelp(helpForm, true);
}
I'm not really sure of where to proceed from here. When I show the helpForm, it obscures / overrides the existing UI and all I get is a gray, empty WPF window with no help file.
Any takers?
If you include System.Windows.Forms.dll you can also do:
System.Windows.Forms.Help.ShowHelp(null, #"help.chm");
Also, there's an article here about adding a context sensitive help system to WPF.
Call me crazy, but couldn't you just do:
System.Diagnostics.Process.Start(#"C:\path-to-chm-file.chm");
I am trying out Easy Help with WPF, which also addresses context sensitive help based on key words. So far it seems good. All I need to do is get cracking and write some decent help!
You can use http://www.pinvoke.net/default.aspx/hhctrl.HtmlHelp to open chm help at specified topic and to have more control of how chm window shown.
How about using the Help class instead of opening the file externally

Categories