Silverlight TextBox cant get focus - silverlight

I have several controls in my silverlight view including telerik and my own controls(Custom controls).in this view there is a TextBox called AppointmentSubject which needs to be focused when i open this view.this textbox is also a custom control.I did following thing inside the View_Loaded method.
System.Windows.Browser.HtmlPage.Plugin.Focus();
//TextBoxName.Focus()
AppointmentSubject.Focus();
But AppointmentSubject only gets focused when i open the view second time.Any idea how i achieve it right first time?

Related

disable all input controls in a WPF Window

Is there a way to make an entire WPF Window inert after a button click?
The window is invoked via Window.ShowDialog() and after use, the window is no longer needed for interaction but I leave it open to remind the user of the inputs in TextBox's, ListBox's, and give visual feedback via OxyPlot and so on. I leave it to the user to close the window manually.
One solution is to disable all buttons but that's tedious and it still leaves TextBox's functioning. That's not optimal because for anything to be functioning creates the wrong impression that the Window remains for anything other than looking at. It would be better for every control to be non-functioning by a single setting.
I did it by putting a name on the WPF window code behind and then setting .IsEnabled false upon the appropriate button click. All buttons, combo boxes, text boxes, and even OxyPlot became inert at that point and most parts were greyed out.
Consider creating a dedicated boolean dependency property in your code-behind or viewmodel and binding IsEnabled of every TextBox to the property.

wpf nested popups

I'm developing a custom control which has a button that opens a popup.
When that popup contains another instance of my custom control (which also has a button that opens another popup, e.g. a calendar) some problems occur.
The second (nested) popup won't act as suspected. Clicks don't work, won't close, when parent popup is closed.
Are there any specific best practices when using nested popups?
I had the same issue. We have a custom DropDownSubsetSelector control in our wpf controls library. This control has a Popup in its control template with StaysOpen="False". Today I had to put this control on a custom view that is located inside wpf's Popup control with StaysOpen="False" and was wondered of this unexpected nested Popups behaviour. My workaround for this issue was to inspect Microsoft's source code of a classical ComboBox control. You can find it here Combobox Source. As you can see its behaviour on a Popup control is exactly the same you expect from Popup being located on another Popup, and it's template has Popup inside (dropdown for selectable Items).
You must subscribe to events MouseDownEvent and LostMouseCaptureEvent and deal with mouse capturing for proper handling of MouseDownEvent outside of Popup control's area. Inspect and just copy some source code for your nested ExtendedPopup. You can inherit it from classical Popup.

Pass a value from child to parent in Silverlight

I am working on Silverlight project.
I added a custom user control (Say, control1) which has a text box and button to a xaml page (Say, Page1).
Now what I want to do is when users clicks on the button, i want to pass the value in the textbox to Page1 and do something.
So basically, I am looking for a way to pass back a value from child to parent page in Silverlight.
Thank you.
You should look into the Model View ViewModel (MVVM) pattern. It works very well with WPF and Silverlight.
http://en.wikipedia.org/wiki/Model_View_ViewModel
http://karlshifflett.wordpress.com/mvvm/ (lots of good information and demos)
You can do this through binding. Bind the Text value of the TextBox to a string property in your ViewModel and use that property throughout the code.
All the controls within your user control are accessible within your main page. If possible, write the click event of the button within the main page and you'll be able to access any control's property. Hope that work for you.

Navigating a WPF Tab Control from within a User Control?

My WPF application consists of a main window with a tab control which has a series of tab items, each hosting a user control.
I'd like one of the user controls to be able to trigger the application to change focus from the current tab to a different one.
Is there a way for the user control to trigger its tab control container to change to another tab item?
The WPF system provides the RoutedEvent. This special kind of event can be created to be catched by every element in the tree. With this way you can fire the event inside your user control, and catch it in the TabControl that will do everything you need. The tab control can catch the event cause of it lies in the element's tree of your window.
You can start from here:
http://msdn.microsoft.com/en-us/library/ms742806.aspx
You'll need a Bubble Event.
Hope this helps.
You can have a property that binds with SelectedItem property of TabControl.

Auto-complete in WPF - Making a popup unfocusable

I'm trying to create a custom UserControl that will mimic auto-complete as it works within Intellisense using WPF. I'm using a TextBox and a Popup containing a ListBox within my control.
I want to be able to keep keyboard focus set on the TextBox irrespective of whether or not the auto-completion popup is open so that a user can continue typing whilst simultaneously using up/down controls or the mouse to select elements in the popup to autocomplete the text. Is there any way this can be done in WPF?
Check out my article on CodeProject, it addresses the issue of the popup specifically.
A Reusable WPF Autocomplete TextBox

Resources