I have a textbox with a search icon next to it inside of a dockpanel that I use in every page of mine. I plan on hooking up the click of the search icon to a command and on each page it brings up the same popup with a listview, whose contents vary from page to page based on the viewmodel binding.
I would like to be able to centralize this text+search control so I can re-use the control and include it in each with a line or 2 of code - the inclusion such as and the line for binding to a different search method (if necessary).
What is the best way to do this? Create a custom or use some kind of template approach?
Please advise and if possible, describe the design and provide an example.
Thanks in advance
I'm sorry if this is a duplicate, but I couldn't find anything relating to it.
I'm trying to create an XpsDocument from a custom control that I have. The custom control already defines properties for a header and a footer, along with the body.
The idea is to be able to use that same control (or derivatives of it) as an input to some custom DocumentPaginator that will create a printer-ready version of that "report", with the header and the footer put on every page, and the controls, inside the body, showing in full (I don't want to create a bitmap of the whole control, then scale it and cut it where the page ends).
Any ideas on how I can split the contents of a user control into pages?
Or suggestions on a different way to achieve the printing of the control onto pages?
Thanks a lot in advance
Check of VisualDOcumentPaginator;
http://www.codeproject.com/Articles/164033/WPF-Visual-Print-Component
Is there a free implementation of the text box in Blend's property grid that allows you to change the number by clicking and dragging? Or perhaps another way to ask is what kind of control called so I can google it?
just try this
http://www.codeproject.com/KB/WPF/MicrosoftBlendStyleTextBo.aspx
It's called a numeric UpDown control. (Terrible name, I know).
MS has a sample implementation for WPF, although I think you'll have to provide the draggable part yourself.
What would be a good approach to display and edit large amount of unformatted text (just like notepade does) using WPF? Loading a big string into a TextBox makes the UI unresponsive. The overall performance is not nearly comparable with TextBox Controls of previous Microsoft UI Frameworks.
What options do I have to solve this problem. I do not want to block the UI thread while the text control loads the text. Also I might need some sort of "virtualization" because it might not be a good idea to load the whole text into the control (I guess that 20MB of text would create a lot of glyphs even if they are not visible). It seems that TextBox doesn't even have an AppenText() Method anymore so I don't even have a way to control asynchronous loading of the text.
Isn't this a common problem? It seems that WPF does not provide anything for this out of the box. Why is this so?
AvalonEdit, the text editor in SharpDevelop, was written completely from scratch in WPF and is optimized for large amounts of text. It doesn't support rich text (although it does support syntax highlighting and other cool features such as folding). I think this might fit your bill perfectly.
Here is an article on the editor written by the developer:
http://www.codeproject.com/KB/edit/AvalonEdit.aspx
I am not sure if this helps, but have you tried using FlowDocumentPageViewer and FlowDocumentReader?
It also has very good annotations support and looks ideal for loading documents in text format.
The problem is that the TextBox is a single container element. List controls, such as ListBox virtualize very well because of container recycling. There really isn't anything simple that you can do to speed up the TextBox.
But the TextBox control does have an AppendText() method:
TextBox tb = new TextBox();
tb.AppendText("Hello");
So yes, you can use this to dynamicly add some text just like you mentioned.
You can just use a textbox with a style that gives the user more room to view the text. There are probably more advanced controls from Telerik and others but if you don't require editing options that should suffice.
You could always mix and match technologies: you could drop a WinForms TextBox onto a WPF parent. You lose things like styling, opacity, animation, transforms, etc., but if all that matters is editing text, the WinForms TextBox does that just fine.
Have you tried the WPF RichTextBox? You'll definitely want to read up on the FlowDocument information if you go this route.
You could use FlowDocument, but this doesn't work out of the box to bind to the Document property of a FlowDocument in MVVM.
Another solution is using FlowDocumentScrollViewer and bind to its Document property.
(or you could even use a FlowDocumentReader and bind its Document property, similar to the FlowDocumentScrollViewer. This gives you a different UI.)
The View:
<FlowDocumentScrollViewer Document="{Binding FlowDocument, Mode=OneWay}" />
The ViewModel:
FlowDocument fd = new FlowDocument();
Paragraph p = new Paragraph();
Run r = new Run();
r.Text = "large text";
p.Inlines.Add(r);
fd.Blocks.Add(p);
FlowDocument = fd;
private FlowDocument _FlowDocument;
public FlowDocument FlowDocument
{
get{ return _FlowDocument; }
set
{
_FlowDocument = value;
NotifyOfPropertyChange(nameof(FlowDocument));
}
}
see also this for extra performance tips: https://learn.microsoft.com/en-us/dotnet/framework/wpf/advanced/optimizing-performance-text#flowdocument-textblock-and-label-controls
How about trying something like this:
Keep the whole string in memory but show only a 'slice' of it in the textbox. Size of the that sliced string would be dynamically calculated depending on the size of textbox, font size etc.
Of course this involves a lot of not trivial code for proper displaying, synchronizing and so on, but it seems the way to go.
One other option is to use Scintilla.NET. It has the best performance for large amounts of texts I have seen so far. Loading large files is almost instantaneous. Even though it is a WinForms control, you can embed it into your WPF window with WindowsFormsHost container. There is syntax highlighting and some other features that should be more than enough for displaying unformatted text. From the downsides - since this is a WinForms control, it overlaps other WPF UI elements. Also there may be issues with resizing the control. Unfortunately, I don't see any better option than using a non-WPF control instead of the default TextBox and RichTextBox.
I'm building simple dictionary application using WPF.
I'm using MVVM pattern, databinding and FlowDocument to display words to user.
UI consists of 2 controls: ListBox and FlowDocumentScrollViewer.
Dictionary data comes from XML file, format of this string may look like this
<b>Word</b> - Some description. Another <i>description</i>. Reference <ref id="123">related word</ref>
The order of HTML and reference elements is not defined.
I parse HTML string, make it into XAML, then from XAML I create FlowDocument object and bind it to Document property of FlowDocumentScrollViewer control.
The problem arises when I need to link ref. elements. (my requirement is when user clicks on reference link, referenced word is selected in ListBox control and shown in FlowDocumentScrollViewer)
My question is there a way to dynamically create "hyperlink"-style controls (with event or commands attached) that would take user to referenced word in dictionary.
Is it possible to solve this problem at all?
There is the Hyperlink text element that has a Command property and a Click event. It behaves pretty much like a button, but it is used inside the FlowDocuments. You can use either method to achieve what you are after, but I tend to prefer Commands. Especially if you are implementing this using the MVVM pattern as you have tagged...