How to handle multiple usercontrols in windows 8? - wpf

In my mainpage i added around 15 user controls and 10 more button images.Whenever click on particular button image displaying corresponding usercontrol.usercontrol having close button to close that control.my question is if user not closing particular usercontrol and click on another button image it's displaying another usercontrol.How to close previuos usercontrol when click on another button image. general idea we can disabling usercontrols by it's visibilty property when click on other button.But in my case so many usercontrols and buttons are there.it's hectic to write code like that for close previous usercontrols .Any other ideas to close that ?

Related

WPF window and element focus

I've got a WPF form inside a window and a short series of events like this:
1) 1st form has series of selection buttons
2) Clicking a button brings up a progress bar window over the existing window
3) Progress window closes and 1st form switches to a new 2nd form using page navigation
The problem is that the 2nd form (and the entire window) no longer has any focus and what's really killing me is that the window is no longer getting OnKeyDown() calls (it's still the top winow). If I hit the tab key the first menu option is highlighted and the following key stroke will fire a OnKeyDown(). Also, if I alt-tab to another app and then alt-tab back to my window it will begin receiving OnKeyDown() again.
How do I figure out where the focus is after the dialog?
If you are using navigation then the focus will have switched to the Page that you have navigated to, assuming that it is Focusable.
You can check that by setting up a breakpoint in a Focused event handle for the Page.
Alternatively you can use an explicit control.SetFocus() in the page.Navigated handler.

Displaying a modal dialog (ChildWindow) from a user control

I have a user control that has a Grid as a main container. This control needs to display a modal dialog. However, when I show the dialog (implements ChildWindow) from the control, nothing happens, no errors and no dialog.
MyDialog dialog = new MyDialog();
dialog.Show();
If ChildWindow is something that can only be displayed from the main page and not user control, what's my alternative?
Solved the problem by creating a user control and putting it in the same grid location as the original control with Visibility:Collapsed. Every time I'd need a modal dialog, I'd disable the user control that is visible and set Visibility:Visible on the modal dialog user control.
This blog post helped a great deal: Silverlight Tutorial Part 6: Using User Controls to Implement Master/Detail Scenarios

How can I prevent events being fired on the Winform when I click on a WPF popup?

I have a wondows form which contains a WPF control as well. When I click on the control it brings up a WPF popup control with a listbox. The goal is, when I select an item on the listbox, the windows form will be repopulated accordingly and the popup should get closed. The current implementation with SelectionChanged on the listbox works fine.
Here is the problem. The popup is big and covers some portion of the winform which contains some links. Now, when I select an item on the listbox, the popup closes after doing necessary actions, but if there is a link just below the popup (on the winform) that is under the cursor (when you selected the item on the listbox), that link is also taking the click event.
Is there any way to prevent the links getting clicked when I click on the popup? I have to close the popup though.
I think I figured this out.
SelectionChanged gets executed when we press the mouse key down and before we lift it.(Mouse key up). The popup gets closed in SelectionChanged before we lift the Mouse key. So, when we leave the mouse key, the keyUp event actually gets fired for a link on the Winform as the popup has been closed by now.
I moved the logic from SelectionChanged to PreviewMouseUp and the popup stays till I leave the mouse key and therefore the links on the Winform do not get the event. Of course, I check whether the selection has been changed or not.

Buttons keeping their focus class after losing focus

I have some buttons in a bottom toolbar of a gridpanel that control adding, and removing records from the row-editing grid.
The handlers are pretty simple: "new" button creates an instance of the model, appends to the grid and then opens a row-editor on the new row; "edit" button just opens the selected row's row-editor; "remove" destroys the record from the store and refreshes the grid view.
For some reason these buttons don't lose the focus class that gives them a border when they have the focus. Here is a picture:
In the picture both the "New" button and the "Remove" button have the focus class, when I press the "Edit" button it also keeps the focus classes even after doing a complete row-edit operation and closing the row-editor.
I did find that when I mousedown on one of these permanently "focused" buttons and then mouseup away from it and then click something else the focus class goes away.
I know that I could put a blur handler for all button components in my respective controllers but I would have thought that this functionality was built in so I am asking to see if there is something I missed somewhere in the docs.
The classes that it won't let go of are these:
x-focus x-btn-focus x-btn-default-toolbar-small-focus
This is with ExtJS 4.1.0 in FF10 on Windows 7. But I did notice similar behavior in ExtJS 4.02 and 4.07, just haven't needed to handle it until now.
I found out what it was:
At some point in the handler chain for each of these buttons the button gets disabled. When a button is disabled in ExtJS it prevents the blur event from firing.
It was necessary to disable the buttons so the solution to simply add button.blur() in the handler was the correct way to do go about it.

How can I float buttons on top of controls when the mouse enters (WPF)?

I want to make a control which will work like the tab header in Visual Studio 2010.
When you have a few tabs open (MainWindow.xaml, MainWindow.xaml.cs, etc.) only the active tab has a close button visible, but when you hover the mouse over an inactive tab the close button appears, which means you can close any tab with one click.
It probably will be a border with text under the floated buttons.
All WPF controls are containers, you can put a button inside a button for example. You can have a layout manager to a control with the items you want in it.
For what you are asking about you could have a user control that has a TextArea and a Button in a StackPanel. Then hide the button. You then have the user control register for its MouseEnter and MouseLeave events and when the mouse is over you make the button visible, and when it leaves you hide it again.

Resources