I have a list that the user can filter in several ways. two of which lend themselves to combo boxes and two that need to accept user input. For example, one textbox allows the user to type in any part of a list item's description, and the dialog will only present items whose description contains the text entered.
It is a dialog 'picker' type of window, so space is at a premium. I'd like for the text boxes not to require a traditional label. Instead, when the dialog is first invoked, the label (ie, "Description") is grayed out, centered, and in italics. Maybe a tool tip to further make it obvious to the user what it's for. When the user starts to type, the faux label disappears and the entered text is normal left aligned text.
Does wpf / silverlight have any native support for doing something like this? I guess it could be a combination of styles and eventing. I'd rather not invent any wheels that might be out there (I got the idea specifically from looking at Tortoise' "Show Log" window, but I've seen it before).
Does anyone have any sample code they can share to do this? Or a an alternative idea that also saves space and simplifies the layout?
Cheers,
Berryl
Kevin Moore's InfoTextBox, which is part of his Bag-O-Tricks is the kind of thing I was looking for, almost exactly. This is also the 'watermark' (great name - I would have found this sooner if I had known that) text box from another post.
Related
I'm currently spiking with the WPF RichTextBox before I decide whether or not it can be used in a project of mine.
What I need is to have elements of text representing various objects (other texts or objects), a bit like a WIKI but not quite. Clicking on such a text will make stuff happen, like navigating to other texts or providing additional options.
Anyway, as these little text bits represent other objects I would like to protect them but I have succeeded with this only in part: The user cannot position a caret inside such a text element and edit/delete it but it is still possible to make a selection and delete/replace it, including my custom elements.
Have anyone travelled down this road with the RichTextBox? My latest experiment was to simply record all custom text elements when being part of a selection and then restoring them after the (destructive) edit. That fell apart because I can't find a way to re-insert my custom inline elements (derived from the Run class). The only way I've found to programmatically insert a Run (based) element at a specified position (TextPosition) is via its constructor.
Well, any hints would be greatly appreciated.
You are really looking for a FlowDocument, not a RichTextBox.
TLDR Version:
I need to find a way to implement some sort of "MessageCenter" where any control can register to receive messages from other controls, without knowing where those messages are coming from (or it can know, so long as it doesn't mean any extra work for me). After typing out this whole thing, I think I've helped myself come to the realization of what I'm after, but if you can recommend some pre-packaged solutions, that'd be great!
So, I'm working on this project where the user gets to make some selections and (more-or-less) layout a page. The rules are very strict, though. At every step, they are given a limited number of ways in which they can alter the page. Think of it as a templating system.
There are a number of interfaces:
ITemplate, IContentArea, and ISpecificControl
Each Template has some number of content areas. Each ContentArea has exactly three specific controls.
They get composited together something like this crude drawing:
The big light purple-ish box is the template.
The yellow, pink, and brown boxes are different concrete types of IContentArea.
The green, light blue, and dark purple boxes are different concrete types of ISpecificControl.
Each concrete implementation of these interfaces will have some number of public properties that I would like the user to be able to set.
For instance:
Green boxes might let you set the font size and font color.
Light blue boxes might let you set the background color.
Dark purple boxes might let you set the image size and margin.
Yellow, pink, and brown boxes let you pick which three specific controls you want to use.
The big light purple-ish box lets you choose how the content areas are laid out (some might have only two or three, maybe they're arranged in a diagonal).
I've made a custom attribute that I can apply to properties in the ViewModel that marks them as eligible for user-changes, and I've set aside some space to dynamically add settings controls. The idea is that the user can only edit EXACTLY ONE item at a time. When they select it, I'll use reflection to examine the public properties of the control's ViewModel and find all the properties that are marked with the editable attribute, look at their types, and dynamically generate controls to edit them (with bindings, of course). We'll call this the "SettingsWizard."
So the problem is really two-fold:
1st: How would you recommend I limit the user to only selecting a SINGLE box at a time? Clearly I need some sort of application-wide event or messaging. What form would that take exactly? And how would I register my "SettingsWizard" to pick up on these messages. I feel like this is going to be something really simple, but I'm overlooking it because it doesn't feel right, or clean.
Anything that let one of these controls send out a message that says, "Hey, I'm the last one to get clicked on. If anyone else was selected, now you're not," would solve the problem, so long as the receiving controls didn't have to know about where the message was coming from.
I was thinking some sort of static "MessageCenter" where when each control is created it registers to be passed messages (in it's constructor) using a defined interface, and any control has the ability to send out a message to the MessageCenter, which would then pass it along. Does that sound about right? I feel like something of this nature already exists. Like the features in Prism (but I don't really have the need for any of the rest of the features).
2nd: How would I let my "SettingsWizard" know that he's got a new item he needs to display settings for? Presumably, a solution for the first item can also be used to solve this one. It's just a different kind of notification.
Based on your TLDR paragraph, I'd recommend taking a look at the event aggregator pattern. If you're looking for an existing implementation, you could take a look at Prism's. I think Prism's is a little over-engineered and have previously posted a simpler implementation.
I was thinking of ways to implement a generic View search. What I mean here is say a Window has many controls (including usercontrols,customcontrols, etc). I want to implement a generic search box on the top of window which searches any Text in the window and highlight them.
I wanted to know is there a generic way of doing this or has anyone tried such UI based search.
I was searching through internet and found some nice links like below::
http://khason.net/blog/search-and-highlight-any-text-on-wpf-rendered-page/ which says search and highlight any Text in WPF rendered page but it doesnt work when there are lot of UserControls and CustomControls.
I myself did some research and thought of going through the VisualTree,LogicalTree, etc but I did not find them satisfactory.
Some say do it using attached behaviors or by data binding but that also did not help me. Because even if i achieved search using this technique, the problem is highlighting. Say there are 4 TextBoxes having different background colors and I highlight background to Yellow when Text is found, I have no way of removing the highlighting when Text is not found because I don't know the previous background color of TextBox.
Ok , enough of my thoughts. I would like to simply accept I am going nowhere in my thoughts. So people I want some guidance in implementing UI search. Also if you people can tell me how I can make it generic, it will be useful!!
Please refer this control
http://www.charlespetzold.com/blog/2009/10/Using-Text-Outlines-in-Silverlight.html
The formattedtext control is a shape which helps to generate the shape of the text with proper geometry. I would like to make this control act like a text box with cursors and features like typing in from keyboard.
Right now I use an invisible text box with a formattedtext control to act like that. But the cursor position always creates a problem when the size of the text is not equal to the size of the rendered text as shape.
Can anyone please show the way to achieve this.
Well, I built a syntax highlighting textbox using the method you describes.
Actually, at first I wanted to rebuilt everything too, but I thought : I have to build the caret fonctionnalities, the selection brush, manage a lot of different events, like selection with mouse or keyboard, deletion, Copy/Cut/Paste, etc etc...
That's a LOT of work, and windows users are used to select text in textboxes for instance, so this complex implementation cannot be left unimplemented. We must follow some Microsoft guidance on how a textbox must feel.
Actually, I think that building a new textbox from scratch is not the way to go. I suggest you to continue on your current method. If you have different fonts in the same textbox, use a RichTextBox, and handle the font changes in the textbox as well as in the formatted text.
Also, a good think to implement is to only draw the visible text with the formattedtext (but only if the user can write several hundreds of text lines).
In order to make a convenient UI for an .Net 2.0 Winforms application I am working on, I have need for a control that I'm pretty sure goes beyond the "out of the box" behavior of any standard control. A mock-up of what I'm trying to achieve follows:
Mock up http://www.claware.com/images/temp/mockup.png
Essentially, this part of the application attempts to parse words into syllables from tribal languages (no dictionary to refer to; any and all unicode characters are possible.) By the time the user gets this far, he has already defined the vowels / consonants in his language and some other configuration. There is then an iterative process of (1) the application guesses which syllables exist in the language based on some rules, (2) the user refines the guesses, selecting the correct parsings or manually parsing a word, (3) the application "learns" from the user's feedback and makes smarter guesses, (4) repeat until the data is "good enough" to move on.
The control needs to present each word (the grey headers), then all the syllable break guesses (the white areas with dots separating the parts of words.) There is also a way to manually enter a parsing, which will display a text area and save button (at the bottom of the mockup.) When the user hovers over a guess, the background changes and "accept / reject" buttons appear. Clicking on the accept, or entering a manual parsing, removes the entire word from the list. Clicking the reject button removes just that item.
I'm by no means 100% sold on the formatting I have above, but I think you can get a general idea of the types of formatting and functional control I need. The control will also scroll vertically--there may be thousands of words initially.
My question for you experienced WinForms developers is: where to start? I would really, really like to stay within the .Net core framework and extend an existing control as opposed to a third-party control. (At the risk of starting a religious war: yes, I suffer from NIH-syndrome, but it's a conscious decision based on a lot of quick-fix solutions but long-term problems with 3rd party controls.) Where can I get the most "bang for my bucK" and the least reinventing the wheel? ListView? ListBox? ScrollableControl? Do I need to go all the way back to Control and paint everything manually? I appreciate any help that could be provided!
[Edit] Thanks everyone for the ideas. It seems like the most elegant solution for my purposes is to create a custom control consisting of a FlowLayoutPanel and a VScrollBar. The FlowLayoutPanel can contain instances of the custom controls used for each word. But the FlowLayoutPanel is virtual, i.e. it only contains those instances which are visible (and some "just out of scroll"). The VScrollBar events determine what needs to be loaded. A bit of code to write, but isn't too bad and seems to work well.
I would look at the TableLayoutPanel and FlowLayoutPanel controls. These will let you organize a series of controls with moderate ease in a vertical fashion. I would then create a UserControl that consists of a label and 2 buttons. The UserControl will expose properties like Text and events that are exposed for the button clicks.. For each entry in the list, you will create an instance of the UserControl, assign the text value, and handle the click events. The instance will be placed in the Table/Flow panel in the correct order. Both of those layout panels do allow for inserting items between other items so you can add/remove items from the list dynamically.
Edit:
Given the length of what you are trying to render, I would consider using the DataGridView and do some custom rendering to make it perform how you want it to work. Using the rendering events of the DGV you can merge columns, change background colors (like highlighting the dark gray lines), turn on/off the buttons, and handle changing the grid into edit mode for your rows to allow modification or inserting of new values. This method would easily handle large datasets and you could bind directly to them very easily.
Well, this certainly looks like a candidate for a custom component that you should be creating yourself. You can create this using standard .Net drawing commands along with a text-box, and a regular button control.
Now you want to find out where to start.
Create a Windows Forms Control Library project.
Drop in the textbox and the button control.
The panel drawing code should preferably be done by code. This can be done using the regular GDI+ commands.
Edit:
Here's another idea, and one that I've practically used in my own project with great success.
You could use a web-browser control in the app, and show your data as html. You could update the source of the web-browser control based on the input in the textbox, and clicking on the links in the web browser control will give you the event that you can trap to do some action. Your CSS will work.
I used this technique to build the 'desktop' in an app I made called 'Correct Accounting Software'. People loved the desktop so much that it is one of the best loved features of the app.
Here's how I would do it:
Create a custom control. In this custom control, have a ListBox atop a LinkButton, and when the LinkButton is clicked you can make it give way to a TextBox. The ListBoxes will have the top row unselectable... you can probably get the rest from there. When you get your list of words, fill a Scrollable of some kind with one control for each word:
(foreach String word in words){
myScrollable.add(new MyComponent(word));
}
From there, I'm not sure what you want to do with the boxes or the data, but that's my initial idea on the UI setup.
Use the WebBrowser control and generate the HTML markup into it using DocumentStream or DocumentText.