This question already has answers here:
How can I create a click event on a custom user control?
(3 answers)
Closed 2 years ago.
I have created some User Controls to be used like buttons. The problem, is that UserControl doesn't have the Click event, only the MouseLeftClickDown and MouseLeftClickUp.
Both events are great for triggers and visual animations, but I really need the Click event.
For example, I have a user control for closing the window. If i use the MouseLeftClickUp event to close the window, the window will close when the user does a mouseleftclickdown in any part of the window, and releases in the usercontrol. This is not safe.
I know this question has been asked a few times, but I haven't found any good answer yet. Is there any simple way to achieve this? I´m really trying to avoid Custom controls, as I don't fully understand them. I´m just starting with WPF.
You can create your own routed event, or I think you can use Button.Click in your UserControl XAML as an attribute. Don't quote me on that, I've seen it somewhere.
See this thread
How can I create a click event on a custom user control?
Related
This question already has an answer here:
Winforms Button Right-Click visual feedback (Show button in pushed state)
(1 answer)
Closed 5 years ago.
I'Ve got a winform application where specific Buttons should be visibly pressed whenever a specific key is pressed.
Capturing the key is not so much a Problem, but I did not find a method that allowed me to make it visible that a specific button as been "pressed".
(Even with button1.PerformClick() there was no visualization of the "click").
Is there any way to accomplish this?
You can use Control.Select() to activate the control.
I have a class that is inheriting from a UserControl. I am showing this class in a WPF TabControl as a tab. The tab has a small x and can be closed by clicking on it. I need a way to do some cleanup code before the tab is destroyed.
I don't believe I can use the Unloaded event to do this because the Unloaded event is called when the UserControl is being destroyed and it is also being called when you click on another tab.
Any ideas on how to deal with this situation?
EDIT:
Here is more info.
In my UserControl class I have a 3rd part control that I am using. Basically a graphing control. There are a couple lines of code I would like to run to ensure that there are no memory leaks. If you want to read more about it then this would be the web address that talks more about it:
http://support.scichart.com/index.php?/News/NewsItem/View/21/wpf-xname-memory-leak--how-to-clear-memory-in-scichart
You can have a look at the way I have done this in the dragablz TabControl on GitHub.
Essentially the TabControl listens to a RoutedCommend raised from the close button, then calls an optional callback which enables a MVVM view model (or old-style control type code) to dispose an associated view model, or perform any other tidy up code you want to do (or indeed cancel the close operation).
In the example project file on GitHub, look for ClosingItemHandlerImpl and work back from there.
http://github.com/ButchersBoy/Dragablz/blob/master/DragablzDemo/BoundExampleModel.cs
ClosingItemHandlerImpl is bound in from the XAML, and the tab control will call it prior to removing a tab.
This question already has answers here:
Capturing mouse/keyboard events outside of form (app running in background)
(2 answers)
Closed 8 years ago.
This might be a common question but I've been searching for almost 30 minutes, and couldn't find what I've been looking for.
In a windows forms application I need to capture the mouse click event both on and outside of the current form. But all the click events that I've come across are attached to the controls, hence when I click outside of the form no event is being fired :/
I am guessing there is a static Mouse object somewhere and I should be able to get the mouse click position maybe?
This is often referred as global mouse hook.
Here's an example: http://www.codeproject.com/Articles/7294/Processing-Global-Mouse-and-Keyboard-Hooks-in-C
The associated project on codeplex: http://globalmousekeyhook.codeplex.com/
This question already has answers here:
Window vs Page vs UserControl for WPF navigation?
(5 answers)
Closed 8 years ago.
I wondered if someone could help me. I'm new to WPF and am currently writing a desktop application, but I cannot seem to get my head around what to use when redirecting someone to a new section of the application.
My options appear to be
Window
Page
UserControl
but I don't understand what the difference between them is, and when I should use each one.
Could someone explain the differences for me, and give an example of what situations/applications you may use each one for?
I'm not sure there is a right answer here, but let me try and guide you. The Window class was created to allow you to have a true window. So, if you need to open a dialog, put it in a Window. Generally you will have at least one Window to house the main form.
A Page was built to be used with the NavigationWindow class. This allows you to build Page classes that are marked up like everything else, but just navigate to them under the covers. This is good if you have a single-paged application where the users just go back and forth between pages (i.e. a wizard).
A UserControl is a way to house reusable markup. These can be housed inside of any ContentControl. These can be swapped out of a "content pane" for example on the main window, like Outlook.
Using that, I hope it helps guide you in the right direction on when to use which. They each have their own uses and are not necessarily exclusive.
Shame I have to install another toolkit, but this seems to be pretty useful: Coding4Fun InputPrompt.
I am having an issue with it though:
There only seems to be functionality for triggering an event when the input is 'completed' without being able to differentiate between whether the tick is tapped or if the cross is tapped.
Rushed into asking for help unnecessarily there. Found a solution, will post below.
Original question:
Users of my application can currently submit messages which they do by tapping on a textbox and typing in the message and then tapping send.
I want to make this cleaner by not having a permanent textbox for this and instead have users tap on a button on the application bar along the button which brings up the keyboard along with a textbox to type into, and when users tap submit the textbox and keyboard disappear again.
I can't see any way of creating a popup with a textbox in it, so how would I do this?
I'm using the WP Toolkit already for a messagebox with a ListPicker inside, by even this toolkit seemingly has no way of adding a textbox.
I'm not sure what your trying to do is even possible. However, what you could do is have a Parent Form which contains your ideal Interface. Within this Parent you could create an Event Handler that is listening for a response.
Then when it comes to that Textbox it actually creates a Child Form or Page. Which they can input their value into. Then the page automatically closes, which then the Event Handler will already know the change for you to manipulate with the rest of your Logic.
As mentioned above, normally you would go to another page. I don't know if my solution is viable, but it does accomplish your goal. I'd recommend possibly refactoring your interface so that it makes it slightly more elegant. That way your logic handles it more elegant as well.
Hope that helps.
Shame I have to install another toolkit., but this seems to do the trick just fine: Coding4Fun InputPrompt.
They've added input.IsCancelVisible = true to add a cancel button and then use e.PopUpResult.ToString() == "Ok" within the input_completed method to only submit when the tick button is tapped.