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.
Related
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.
I want to unload a user control on the click of a button inside the user control. I am calling this user control inside navigation:page for the filtering the rad gridview.
I think Making the visibility collapsed wont unload it.
Any ideas?
Remove it from visualtree. Suppose that your control "myControl" is contained within Panel derivate called "LayoutRoot" then you can do this:
LayoutRoot.Children.Remove(myControl).
I couldnt get the GotFocus() event fired in the WPF window by clicking. But if I click any controls, it will be fired.
My requirement is as follows: I have a hostwindow which has a viewport with two datagrids which can host user controls. I do animations like flip and fade on this user controls. I am using a transparent background(glass effect) for the controls. But when one user control get on top of the other, both of them overlap. So I want to make the top one opaque when the user click on one user control.
Try using the Activated event, as GotFocus is intended to be used only with controls.
I am currently working on a project which has a tab control which contains a Wrap panel which contain a series of user controls. I am looking for a way to allow the user to select one user control and maximize it to the size of the tab control/window.
One thought is to simply remove all the other items from the panel.However I am attempting to use MVVM as much as possible and I'm not sure how much the user control should know about the panel. (The user control will contain a button to allow maximizing)
Is there a way to temporarily remove the usercontrol from the grid and treat it like a modal popup or just to fill the window?
How about having "Visible" or "Maximized" bool properties in the view model for each user control based item, and databind said user controls Visibility property to the appropriate property. Then bind your user controls maximize/restore button to command in the view model to change the VM properties appropriately?
I have an ActiveX control inside a WinForms user control. My WinForms app loves it!
Now, moving over to WPF, I use the user control in a WindowsFormsHost control. Works great..., but I want to treat this control as a single element so the user can neatly hit TAB over the existing WPF controls AND this user control NOT to 'go inside' it. i.e. just treat it as a single control like all the others.
I think what i need is the ability to trap the keys, and in the event handler simply move focus to the next control in the sequence, but I can't seem to trap any keyboard input. Ive tried the WPF PreviewKey.. events and the like, but once the tabbing gets to the control, it seems to stay inside it and WPF events are ignored.
I couldnt find anything on this in many WPF books and the net. Can anyone suggest a way ?
Thanks,
Jack.
Can't you create some sort of a filter by doing a preview mouse down on the panel or window (whatever is the parent of your controls), this way the panel will catch it before the user control and you should set e.handled to true, and if the user control raised the tab event, keep pushing the focus until you get another control. Preview and e.Handled=ture should solve the problem.