What is the best way to detect Ctrl+V in Silverlight?
I want to detect Ctrl+V, to get access to the Clipboard.
if (e.Key == Key.V)
{
if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
{
//do what you want on paste
}
}
You have to use this on the keyUp event. More details can be found here: http://msdn.microsoft.com/en-us/library/cc189015%28VS.95%29.aspx
EDIT
To capture the CTRL+V keypress globally in your silverlight application, is fraught with difficulty. Events start at the child elements and bubble down to the parent controls, so simply handling KeyDown on your root UIElement will not work. Any text input control will first get the event and smother it (by setting Handled to true on the event args.) I think that if you use the DOM bridge and subscribe a handler to the browser KeyDown event for the silverlight element itself that you may actually be able to get to it first, and even handle it completely before any silverlight controls can. I think that would be the easiest way to intercept CTRL+V, but I have not tested it.
Original Answer
You should use the System.Windows.Clipboard class.
GetText, which retrieves text from
the clipboard
SetText, which places
text on the clipboard
ContainsText,
which indicates whether the clipboard
currently contains text
Related
This question already exists:
Is there any way to add TextChanged event to a Label? [duplicate]
Closed 3 years ago.
I've been working on a mobile chat application and displaying the messages in the inbox of a user using a label. I need to detect URLs, tags and some special kind of text. text may change at any time. I need to implement the TextChanged event for the Label. So that I can perform my operations to detect URLs, tags, etc.
All the text in the above image will be displayed using a single label. Whenever the text is changed, the label should detect the TextChanged event and update the colors and decorations of the detected URLs and tags using spans.
We did this in WPF using TextBlock control. Now we have to implement it in our mobile application.
Is there any way to implement the TextChanged event for the Label in Xamarin.Forms.
Fist of all you have to implement label that is capable of converting html tags to formatted text or whatever method you are using. Then you should bind your text to method that collects data from probably remote source. Text changed event handler is used rather to detect user input in XF. I don't know how your application works but, using MVVM models and bindings will save you a lot of frustrations when working with Xamarin UI.
Label.OnTextChanged(EventArgs) Method will be there, you can use this.
Entry1 _TextChanged(object sender, TextChangedEventArgs e)
{
if(.... put some condition here....)
{
entryField.Text = e.OldTextValue;
}
}
Reference link - https://learn.microsoft.com/en-us/dotnet/api/Xamarin.Forms.Entry.TextChanged?view=xamarin-forms
Triggering edit mode in dojo dgrid with mouse event is easy. Here's what I have done:
editor({field: "checkNumber",label: "Check Number",editOn: "click"})
However, i want to trigger edit mode using keyboard. Specifically, i want to go into edit mode when I press the space key. How can I programmatically set a cell to 'edit mode' or 'non-edit mode'?
When you add one or more editor columns to a grid, it makes the edit method available on the grid instance, which you can call with a cell element (or event referencing one) to programmatically shift focus to the editor for the cell.
Meanwhile, the Keyboard mixin has an addKeyHandler method which you can use to add handlers to respond to keydown events for particular keys.
Combining these two things, you can easily do the following to cause the grid to edit the focused cell when space is pressed:
grid.addKeyHandler(32, function (event) {
grid.edit(event);
});
(edit should have no effect for cells in non-editor columns.)
An alternative solution could be to create an extension event which triggers either on mouse click or on space keypress, and pass that to editOn instead of 'click'.
var grdobj = dijit.byId("...");
var editCell=grdobj.cell(rowNo, "checkNumber");
grdobj.edit(editCell);
Instead of cell function, you could make use of right, left, up, or down functions.
Hope that helps.
I have a windows application with a tabcontrol. One of the tab of the tabcontrol has a webbrowser control.Now the issue that I am facing is when the focus is inside the webbrowser control, the normal Ctrl+Tab functionality of the tabcontrol is not working.I want the Ctrl+Tab to change the selected tab of tabcontrol even when the focus is inside webbrowser control in selected tab.How to achieve this ?
I have already tries overriding ProcessCmdKey.but it does not get hit when focus is inside webbrowser control.
I also tried registerhotkey method ,it works but it locks the Ctrl+Tab hotkey within my application & system doesn't respond to any other Ctrl+Tab presses outside my application when application is running, which is expected behaviour of registerhotkey.
Here is the code you need:
If WB.ContainsFocus Then
MsgBox("We have focus, disappearing...")
WB.Document.Body.RemoveFocus()
End If
Now, the question is, when to run that code. If you put it in the WebBrowser1_GotFocus event, you'll need to turn it on and off. Turn the code off if the user is interacting with the WB Control, and turn it back on when they are not and when you expect to be experiencing the problem you've mentioned.
Of course, you could add another line to ensure a particular control/tab/panel etc gets focus after you remove focus from the body. Also, here are 3 other SO questions that have answers which may help you, but these will take you in directions different to the direction I've provided, probably due to the fact that the questions are not identical to yours, but are similar enough to be useful (not listed in order of preference).
Prevent WebBrowser control from stealing focus?
Webbrowser steals focus
Focusing WebBrowser control in a C# application
UPDATE:
I just wanted to add, instead of the .Body.RemoveFocus() you could do this:
WB.Document.Body.Parent.RemoveFocus()
Which I prefer, since the .Document object didn't have an explicit .RemoveFocus method on the intellisense I was gettign in VS2012 RC. This is probably referring to the HTML tag (and not the .Document object) and since the html tag is the only parent to the body tag, it makes sense, and there is no "HTML" object directly available in the intellisense under object, since you can get it via other means, so it's just more convenient doing it this way.
Cheers, and let me know if you need more info on anything.
I have a WinForms application with some business objects which implement INotifyPropertyChanged and hook the PropertyChanged event via some controls & BindingSource on the form which raises an event back to my business objects layer...
There's just one issue - everything works fine, except only when the control loses focus. E.G., the user changes some text field, but he has to actually click on some other control somewhere BEFORE he hits the 'save' button (e.g. he has to cause focus on another control).
Is there a way to wire this up to OnClick or something so the change is propogated to my business objects layer as the user types the text (or even after he changed a drop down value) so I don't have to force the user to click on a different text box before he can save?
Googling has lead me nowhere but to examples on how to easily do this in WPF =(. But no WinForms examples...
Please Advise,
Drew
If you are using Binding class to connect object to UserControl, you may try to set binding's DataSourceUpdateMode to OnPropertyChanged.
Please, note that in this way you are writing data to your object before validation. This may be unsuitable for some tasks.
Is it possible to capture keyboard events within a diagram produced using Dojox.GFX?
We have a simple graphical application which involves some shapes drawn on a surface. We would like to add some simple keyboard interaction, e.g. using the Delete key to delete a shape, and using "Ctrl+A" to select all shapes.
I have tried adding dojo.connect and shape.connect statements for "onkeypress" and "onkeyup", but they never seem to get triggered. We are already capturing mouse events and these are working fine.
Thanks
David
Keyboard events are not pointed, they are essentially global. You should catch them globally attaching a handler to document or body.
Thanks, now working!
In my case this was a portlet so the <body> tag was not available, but I used a <div> tag instead:
<div id="queryPortlet" onkeydown="handleKeydown(event.keyCode);" onkeyup="handleKeyup(event.keyCode);">
The other thing I had to watch for was not intercepting keystrokes if the focus was in a text input field. I had to write some code to keep track of when the focus was in a text field, by adding onfocus() and onblur() handlers to all such fields. This was a slight pain but was the only way I could find to do that.