Accessing Silverlight Text Property in Loaded Event - silverlight-4.0

I am subscribed to the Loaded event of a Silverlight TextBox. I would like to access the Text property in this event. It works properly when I directly set the text, but when I am binding the Text property it is always empty. Is there way to do this without subscribing to the LayoutUpdated event instead?

please try using TextChanged property instead. :)

Related

How Do You Use Remove Handler

I ma using DevExpress controls (which doesnt matter for this example). I have a lookupEdit control and I never want the EditValue_Changed event to fire. Can I use RemoveHandler to do this? If so can someone give me a code example of doing this? Should I put RemoveHandler in the load event of the user control I am creating? Or does it go in the EditValue_Changed event of the lookupControl?
THIS IS A WINDOWS APP NO POSTBACK....Sorry
You can use RemoveHandler from any event you add to an object within one of your own classes. If the event is defined and being handled within a class you do not have access to, you will not be able to remove its handler events.
It would be instructive to learn where this EditValue_Changed event is firing. If it is firing within your application, then you must have wired it up either in the designer or in the code (which means you should be able to call RemoveHandler without difficulty). If this belongs to a 3rd party library and is auto-configured, you may not have this access.
You can't stop the control from firing the postback, but you can just not wire up an event handler to a control's event. You don't need RemoveHandler to do that; just don't attach to the event... But it seem like the issue is the postback, DevExpress should have a feature in there to fire a client-side event, and keep that all on the client and not have to worry about a server-side postback.
If this doesn't help, could you explain more about the problem?
HTH.
You might be able to subclass the control and override the method(s) that trigger the EditValue_Changed event to fire. If you have access to the source code, find where its being called and if that code can be overridden.

I changed the SelectedItem via a Binding. Now how do I move it into view without code-behind?

I've got a DataGrid with a Two-Way Binding on SelectedItem. I can change the SelectedItem in my ViewModel, but the DataGrid won't ScrollIntoView automatically.
Is there a way to do this without using a code-behind event handler that calls ScrollIntoView(SelectedItem), or should I just give in and use a little code-behind?
Check http://www.codeproject.com/Tips/125583/ScrollIntoView-for-a-DataGrid-when-using-MVVM.aspx

How to detect Ctrl+V in Silverlight 4?

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

PropertyChanged Event, raise when OnClick?

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.

Databound User Controls in .NET

I am looking for some information on how to properly implement data binding on a user created control.
My UserControl contains a Textbox, a Button, and a MonthCalendar. I am able to databind to the Textbox inside of my user control, however, I want to implement the databinding on the UserControl itself, and not reference to textbox inside the control.
I have attempted to set a Property as follows:
<System.ComponentModel.Bindable(True)> _
Public Property BoundDate() As DateTime
Get
Return _currentSelectedDate
End Get
Set(ByVal value As DateTime)
SetDateTime(value, True)
End Set
End Property
However, when I add a binding source to the control, the field does not populate with the data, it remains blank. Do I need to do something to make the data appear afterwards?
Can anyone direct me to a good tutorial, or if possible, explain it here.
The project is written in VB.NET.
EDIT: I am implementing the DefaultBindingPropertyAttribute
What is the textbox bound to at this point? I'd suggest the following:
In the user control load event, declaratively bind the text box to a private member variable, e.g. private _boundDate as DateTime
Have you setter in your boundDate property update _boundDate
This looks like a pretty good read, although I haven't looked at it myself