A Question about good Design (.NET, System.Windows.Form.Button, C#) - c#

I was wondering about a smart way to solve the following scenario:
I want to implement an onscreen keyboard with System.Windows.Form. There are a lot of buttons functions to implement and I don't really want to write a callback function for every single button, since they basically all do the same.
Where do I store the 'character' information in the button object, in a solid way, without using too much of a hack?
Or.. generally, can you show me some better approaches to this?

The Tag property of the Button is a good place to store information.
Control.Tag Property via MSDN

Inherit from Button such that you can provide (probably in the constructor) the character code that the button represents. Use that button.
Alternatively, since the button will show it's character in the button text, just get the button text to find out what has been pressed.

There are a number of on screen keyboards out there for WPF already, might want to take a look at those. If you don't want to use them directly, they may at least point you in a direction:
http://wosk.codeplex.com/
http://wpfkb.codeplex.com/

Related

How do I make controls extend passed a control bound or overlap with others?

I have a wpf grid setup where I have two custom buttons that are next to each other. First picture is how the design window looks like, however, functionally, it looks like the second picture. I want them to function like the grid doesn't block them (closely resembling the first picture.)
The current xml I have is based on this MSDM which is very basic.
I do not know how to proceed. Do I have to use a different control panel/container or is there a setting to allowed them to extend passed the grid if the other button isn't above it (like zpanel?)
E: I couldn't find any other questions for this, so please link to any searches/posts with information on it.
Turns out I can use canvas and just do a bit more xml to keep the design the same. I would still like to know if it is possible to overlap them in any way for future use.

C#/XAML Windows 8 AppBar by command?

I apologize if this is a simple question. I'm very new to XAML, and I'm trying to understand app development more.
Basically, I have a section on the bottom of the display reserved for a pop-up AppBar. From what I understand, this pops up on an edge swipe, but I'd like to use some sort of a call to bring it up. This way I can have various varieties of the AppBar pop-up when the situation calls for it.
How would I go about accomplishing this?
OR, is there another approach that might work better?
Thanks for your time!
The page has a BottomAppBar property (<Page.BottomAppBar>). Here you can enter a AppBar control and inside of it any XAML you want. Then you can show and hide anything through the Visiblity property from code. So - you can for example add two Gridcontrols in the AppBar and always display one of them.
If you're looking to create multiple AppBars for use on the same page, you'll have to do so in the code behind. See this link:
http://msdn.microsoft.com/en-us/library/windowsphone/develop/ff431786(v=vs.105).aspx
Once you've created them, set the IsVisible property to true/false to show/hide them.

How to build a "word-by-word" autocomplete in WPF?

I already did some research and ended up with several autocomplete boxes which have one thing in common: they all match the whole expression which has been entered. Sometimes, they seem to be easily expandable, but at the end, they aren't.
However, I need a Textbox which allows the user to enter a word (e.g. "tag1"), displays a popup with some suggestions based on this single word, accept the suggestion with the return key and type in a new word (e.g "tag1 tag2") in the same textbox, with the popup popping up again. (I like the way CintaNotes handles this)
I need this for a tagging interface. It's often faster for the user to write the tags into a simple box, but sometimes, he needs assistance. This is what the autocomplete is for.
I've found some results, which don't work for my purpose (imho):
http://www.wpfpedia.com/item/details/743/wpf-autocomplete-textbox-control
http://www.codeproject.com/KB/WPF/WPF_Autocomplete.aspx
http://www.codeproject.com/KB/WPF/autocomplete_textbox.aspx
http://weblogs.thinktecture.com/cnagel/2011/01/autocomplete-textbox-with-wpf.html
Btw, I really like the way the Tag-Box for SO operates.
Does anyone have an idea? Is there a "out-of-the-box" - solution somewhere, which suits my needs but I didn't find? Or do I have to build one myself?
Thanks! :)
I think you mean a textbox which autocomplete for multiple words.
Like TokenizedTexbox on WPF Extended Toolkit.
this is the page: http://wpftoolkit.codeplex.com/wikipage?title=TokenizedTextBox&referringTitle=Home
Probably you would need to create your own Dictionary object of Key and Value pairs and hook that Dictionary to the textbox events and popup a suggestions dialog that displays the Value(s) from your Dictionary
Check this implementation out: http://code.google.com/p/kocontrols/downloads/list
You may inject your own Search algorithm and your own converter which converts the selected element to text, which you display in the TextBox. You will have to modify it slightly but I think that you might be able to solve your problem by basing your control on this implementation.
I never thought about this type of use case.
Can't you use different textboxes for the different tags? Something similar to how goole code does it?
If you have time, you can use the RichEditControl or TextBox and apply the same pattern used in Intellisense engine or Code Completation enabled editors: Hook the text changes events, Recogize context (last/current word) and display the options list on popup control. And optionally, on commit (detect acceptation or space key), apply the format to the word.

how to make active while in background c# xaml

I made a virtual keyboard in xaml c# using WPF. Its totally working and great. However I would like to add a few quality of life things if possible. Is there a method of having it take keyboard input while in the background and your primary application is say notepad. The virtual keyboard highlights keys as they are pressed is why this is important.
Barring this is there a way to make the text in a textblock selectable for copy paste (I can track what was typed and post it in one, BUT THE TEXT SHOULD NOT BE DIRECTLY ALTERABLE!!!!, much like a website)
I'd also like to know if there is a way to have the curser default to a textbox rather than having to click it.
You should use low level hooks in your app for show pressed keys.
See a code sample here.
I can't help with the keyboard part, but there are a couple of ways to do the copy only text:
Barring this is there a way to make
the text in a textblock selectable for
copy paste (I can track what was typed
and post it in one, BUT THE TEXT
SHOULD NOT BE DIRECTLY ALTERABLE!!!!,
much like a website)
For one, you could just create a TextBox that is marked with IsReadOnly=true. You could also display a FlowDocument with a textblock on the inside.
As for defaulting (I'm assuming you mean focus), this might help:
http://msdn.microsoft.com/en-us/library/aa969768.aspx

Find as you type in C#

Im trying to emulate a 'find as you type' function like that of the address bar ("awesome bar") in FireFox. I want a suggestion box to appear below a textbox, and the suggestion box contains strings that contain what is in the textbox. I looked at the autocomplete feature of a normal WinForms textbox, but it seems to only search the beginning of the strings.
Has anyone here built or have experience with implementing something like this?
edit:
Some clarification- It is a WinForms project.
It needs to search inside a string, not just the beginning (which is what a normal textbox does if i recall correctly). And the suggestions should be displayed in a popup like a textbox autocomplete.
You need to handle the TextChanged event for your text entry field, and when the text changes, start a new thread running that will apply the new search. If the text changes before you get your results back, just kill the thread. If the thread returns results in time, display them.
You can get slightly more advanced (e.g. wait for a short time after the text changes so that the user can type a word without you triggering off loads of useless threads) but essentially that's it.
There was a discussion earlier on this topic where the author concluded that you are better off doing the whole thing yourself.
How can I dynamically change auto complete entries in a C# combobox or textbox?
I did something vaguely similar, but more like the iTunesĀ® search box than the Awesomebar. My control used the textbox to actively filter a grid; so it wasn't for autocompletion.
...but... basically I had a DataView of all eligible items, whenever the TextBox's Text changed I'd update the Filter to hide all non-matching items. It worked well and might suit your needs for filtering the data--but not sure how to go about using it as an AutoComplete source for the textbox.
I have done such a thing for an app of mine not too much time ago.
What I did is make my search function in a new thread, so every time I typed a new letter, it called the search function in another thread, so I could keep on typing.
I can post some code if you need, but this should be enough to get you started. :)
Hemmed and hawed about deleting this after I noticed the OP edit mentioned winforms, but I think it'll be useful to anyone who comes here looking for the same but for asp.net apps.
Just because nobody has mentioned it yet, for a webforms app you absolutely want to do this with ajax (.net controls or pure JS, your choice). The feature is often called "autocomplete" and the one thing you don't want it to be breaking the seamlessness by making server round trips at the page level.
I suggest you look at this and this.
I've used Search As You Type in C# and How do I make a Textbox Postback on KeyUp?
Basically you use the keyup action to call a postback thats attached to the trigger to the update panel. then you do your update in the textbox_changed event with the dataview or whatever your backend looks like.

Categories

Resources