Silverlight 3 - Control over wrapping in TextBox - silverlight

Ok I have the following problem in Silverlight. I have a control with 2 columns. On the left is a stack panel with line numbers and on the right is a textBox.
So when I write in textBox without wrapping turned on I can simply create the right count of numbers on the left, because I'm searching for '\r' in text.
But when I turn on wrapping I have no control over the count of lines in textBox.
Is there a way to get to that count? Or a way to know which line in textBox is going to wrap?
I hope you can understand what I'm trying to do.

There's one way to do this. You can simulate the word wrap operation in the background using a TextBlock. Here is a good link of the complete solution to this problem.
Extended TextBox control with MaxLines property

Is it not possible to create your items in code before they are passed to the view. This would enable you to bind a list of items to a listview and style them as you wish.

You need to user a value converter to count the number of char / lines and then trim that number if you wish to. Unless you use fixed width, you can't really count or calculte in advancet the size, since each application might be displayed differently (due to different sizing option).
There are two great sample chapters on Windows Phone and Silverlight for Windows Phone on the LearningWindosPhone.com site. There is great Windows Phone Trainng material , and dont forget the Windows Phone Develoeprs Blog

Yes there is a way to get the number of lines occupied by the text in the textbox. It's not that simple though 'coz you have to simulate the behavior of the word wrap in order to count/predict the number of lines generated as a result of a word wrap. I have the solution described here in detail.

Related

ToolTip works very slow for long text (2000+ chars)

We need to use the built-in WinForms tooltip control to display a very long tooltip (about 4000 characters) for one of our controls. But if we do so, the form freezes for a minute or two when we place the mouse pointer into the target control to see the tip. And nothing happens after that.
We experimented and detected that the standard tooltip starts to work very slow when it has about 2000 chars, and the situation becomes much worse when we increase the number of chars. Is it a known issue, and is there any workaround for it? Please, don't suggest to trim the tip text - we need to display the string as is.
When you assign a string of text to a ToolTip, part of the process of drawing it involves calls to USP10.dll which handles Unicode layout of characters on screen. I was able to see this by looking at the stack trace while the program was freezing. The performance of this layout is terrible for long strings.
Disabling Visual Styles for the application (commenting out EnableVisualStyles()) fixed the problem - the tooltip displays immediately, though this is not an optimal solution.
I kept looking and found this page which indicates the problem may be linked to layout of long strings where word-wrap is necessary. By inserting line breaks into the tooltip text, I found that the string displayed immediately. So, if you can determine where to insert the line breaks manually, the ToolTip should display quickly.
What about using another Tooltip , i.e. HtmlToolip?

How to Move content to next page in WPF Form

I am new in WPF if there is something wrong please co-operate.Here i require some idea from experts.
I am working on one application in which i have to show some content on WPF form after filling the fields present on the form.On the same form i also have a print option.
Check this image.This is my form here part in the red block is generated at runtime.When i click on the print button it only show the visible part on the paper and skip the remaining part.
Problem :
How i can move the remaining part of the form which is under scroll to next page when i click on print.
For example in the given image we can see only 2 bulls eye completely and next 2 partially.How i can shift this remaining part to next page only when i click on print.
The answer is quite easy : don't rely on your window to do the printing, but build the visual you want then print it.
For instance, you must have a function that creates dynamically the circles and so on, then adds them to a Panel. What you might do is to print the Panel.
Or if you prefer, you might build Dynamically a new window, where you put all the Data you want printed as you want, then print the window. The advantage of this method is that it is more flexible for the content (if you want a header/footer) and also you can watch the content easily for debug. Note that even if the Window content is dynamic, you can have a base window for printing that avoids you to do too much xaml with code (expl : you might have TextBox bound to a PrintTitle property that you setup in the constructor of the Print Window...).
Notice that visual that were not rendered on screen will not print. Be sure, to avoid the common issues, to have a look at this article from this great site, switch on the code, here :
http://www.switchonthecode.com/tutorials/printing-in-wpf
Edit (reply to the question in comment):
1) If you have fixed number of bulls eyes, just make one Window for that number and Print it, this is waaaay easier.
2) To put Visuals in pages instead of rows, you'll have to rely on page Width/Height. What matters is the size of your control vs size of page. In the example, they build (in OnRender) Controls having LineHeight, LineWidth as size. Do the same : Try to put as many line of control as you can such as
(Control Height + margin )*NumberOfControlPerPage < Page Height.
Then you have to change OnRender to render controls instead of Rows made with rectangle+text. Pack your controls two by two in Horizontal StackPanels Then pack those StackPanel into a vertical StackPanel, then render. You have to keep track for each page which control was rendered last, then resume rendering at the following control.
Please follow this link.This is the basic which i got after searching in web world.Using this basic detail you can do any thing with print in WPF

Increasing the size of a WPF application

I've just created my first WPF application (3 calculators inside 3 different tabs).
The entire application has been built using widths/margins/paddings as static values, since I originally didn't know that dynamic values can be used by just putting an asterix after the value.
The client has come back to me though and has asked me to increase the size of the app, that includes form fields, tabs, font-sizes, grids etc...
What would be the easiest (and/or quickest) way to do this? I'd hate to go value by value resizing every single element since there are quite a few.
I can provide code but there is lots of it and I'm not sure of how much help it would be.
Appreciate your help,
Marko
Put it all in one ViewBox, play with viewbox size to change the app size
Write an XSLT transform to take your XAML as input and spit out appropriate modified XAML, which you put back in your app.

Bullets and Numbering in Silverlight

I'm looking for some comprehensive library for Silverlight on bullets/numbering. I've found a few, like Vector Light's RTB control, but most are lacking extended features of bullets/numbering that word processing programs have, like having the First Line Indent of a great value than the Hanging Indent (e.g. first line indent is 1 inch and hanging indent is .5 inch). Another example is customizing the size of the bullet/number Anyone know of good libaries for this for Silverlight?
Check out the ordered/unordered list controls explained in this link. You can extend its functionality to acheive what you intend to do. I have used it to show hierarchical data using nested lists and found it fairly easy to modify it to my needs.
that implementation works for read-only content only.
What if you need to apply bullets/numbering/indent to selected-text in a RichTextBox?
You have to programmatically find Paragraph elements inside selected-text and insert the corresponding character (bullet or number of tab) at the start of each Paragraph element.
Check out here for detailed explanation: http://www.codeding.com/?article=22

WPF What container should i use

well what i want is this lets say i have a "panel" with the width 100 and height 100
now i want to place X objects witht the size 20 so when i add more 5 items it should have all items on one line
|Item1|Item2|Item3|Item4|Item5|
now if i would add one more then i want it to split it to 2 lines with 3 items on each row
|Item1|Item2|Item3|
|Item4|Item5|Item6|
and well i guess you get the point, iv tryed stack panel but i cant get it to work the way i want it to..
Edit:
well it doesnt matter that mutch if each row has an equal amount of items.. so a wrapPanel should do the job next problem -> Here
There's no standard WPF panel that will do this for you. The WrapPanel comes close, but it will not make sure that your rows are even. Your best bet is to implement your own panel. Here's a good example on codeproject
The WrapPanel should suit your needs:
Controls are positioned in either a
stack or row based on the Orientation
property. In addition to stacking, the
WrapPanel provides wrapping support
for contained controls. Thus if more
controls are added to a WrapPanel than
can be displayed by the width of the
WrapPanel, they are wrapped around to
form an additional stack or row.
To be honest, I haven't tried that specific requirement myself.
I guess you could use WrapPanel... but then you would get 2 lines, (5 items and 1 item)..
What would happen if you had, say.. 7 items?
I don't think you will be able to get a container control that does that automatically. You could have a Grid with two rows and a StackPanel in each row. As you add the items you would need to programmatically select which StackPanel to put each item into.

Resources