Activating main window when button is clicked in a user control - wpf

I have a WPF user control with some buttons inside it. I need to intimate the main window when button click happens inside the WPF control. The main window has to initiate some actions upon receiving this message from the button click event inside the user control.

You can add a Click handler to all your Buttons, and in that Click handler, call the UserControl's OnClick method to generate a click event coming from the user control.

Check out Commands:
http://msdn.microsoft.com/en-us/library/ms752308.aspx

Related

event between main form and child control

Hi I have main form in which I am displaying user controls like ManageDepartment. I have few buttons like RESET in main form.
I want to have event in ManageDepartment to reset controls.
When user clicks on Reset Button on main form, the button should call the reset event on displayed control i.e. ManageDepartment
Can any one suggest me how can I achieve this?
If this is duplicate question, please direct me to original question.
You don't call an event. If the user control has a Reset event then that event would get raised by that control.
It sounds more like what you need is a Reset method on the user control. You would handle the Click event of the Button on the form and call the Reset method of the control. In that method you would do as required to reset the control, e.g. call Clear on each TextBox.

How to Create an "Apply" Button on a Modal Dialog Window

I have a vb.net WPF application that has a modal dialog window that has an "Ok", "Cancel" and "Apply" button. The "Apply" button does the same work as the "Ok" button but when the "Apply" is clicked the modal dialog box should stay open. Normally I like to call ShowDialog to display a modal but that results in the modal closing when it returns so I can't use that with a modal the has an "Apply" button. Can someone provide me with an easy work around? The alternative is to display the modal dialog window using .Show but in this case I'm not sure how to properly return values when the user clicks on one of the buttons.
Thanks!
The closing of the dialog is handled by the code that executes when the user clicks the OK button. So you could move all of that code to a function with the exception of the Close() call and the call that sets the DialogResult. Then you can call that function from both the OK handler (or ICommand) and the Apply handler (or ICommand). Then just don't call Close() from the Apply button.
Dialogs with an "Apply" button aren't generally modal, but one approach would be to instantiate your dialog and supply it with a ViewModel via DataContext where your dialog data can be shared between the function calling the dialog and and the dialog itself. Then, wire your "Apply" button to be handled by the modal dialog and whatever ViewModel code you have, perhaps via an ICommand binding.
Let us know if a sample would be useful.

WinForm button click methods are being renewed. with button onclick_1

I just finished completing my winforms app. Suddenly when I was changing background color of gridview. When I started my app for final tests the buttons were not working. I checked their on click code and it was correct. Then I double clicked the button it created new button onClick_1 method. SO now all the buttons are doing it :( I dont' know what to do. Please help
Looks like your events are no longer coupled to your code.
Do this for each of your buttons:
Open your designer
Click on your button
Open your properties tab
In this menu, click on the events button
You'll find your "Click" event.
Click on the arrow and select the correct event.

WPF Popup Activation and Deactivation

Is there a possibility to detect if a Popup is activated or deactivated? Such as the Window-events Window.Activated and Window.Deactivated.
I want to detect if the user has clicked outside of the popup (I can not use the Popup.StaysOpen=false option).
Update
I have forgotten to remark, that I dont want to add any handler or code to a parent-control of the popup.
Capture mouse clicks for your main application window (MousePreview type event) and for popup - when user clicks into popup, main window event doesn't fire and vice versa.
Sounds like you could just use the Popup.Opened and Popup.Closed events.

WP7 - Cancelling ContextMenu click event propagation

I'm having a problem when the Silverlight toolkit's ContextMenu is clicked while it is over a UIElement that has registered a Tap event GestureListener. The context menu click propagates to the underlying element and fires its tap event.
For instance, say I have a ListBox and each ListBoxItem within it has registered both a ContextMenu and a Tap GestureListener. Assume that clicking context menu item2 is supposed to take you to Page1.xaml, while tapping on any of ListBox items themselves is supposed to take you to Page2.xaml.
If I open the context menu on item1 in the ListBox, then context menu item2 is on top of ListBox item2. When I click on context menu item2 I get weird behavior where the app navigates to Page1.xaml and then immediately to Page2.xaml because the click event also triggered the Tap gesture for ListBox item2.
I've verified in the debugger that it is always the context menu that receives the click event first. How do I cancel the context menu item click's routed event propagation so it doesn't reach ListBox item2?
Thanks for your help!
You can get around the problem by doing the following:
In the context menu's Opened handler set LayoutRoot.IsHitTestVisible (LayoutRoot is the default name for the root UIElement) to false
In the context menu's Closed handler set LayoutRoot.IsHitTestVisible back to true
You could try adding a rectangle with a transparent background (important) over the effected area/page when showing the context menu.
I had a very similar issue, but I am using the ManipulationCompleted event as a "tap" detector as the object the ContentMenu applies to is a custom control.
LayoutRoot.IsHitTestVisible didn't work for me, perhaps because it does not apply to Manipulation events. However, it set me on the right path. I just implemented my own simple equivalent of it - I created a boolean variable bCancelManipulation in the page's scope.
In the ContentMenu's Opened event set it to True.
In the ContentMenu's Closed event set it to False.
In the ManipulationCompleted function, the first thing I do is check
if(bCancelManipulation==true) { return; }
It's kind of a hack, but it works great and is quite simple to code - it can easily be adapted to a Tap event too.

Resources