I have two entirely uncoupled WPF windows, however, if something particular is happening in window 1, I do want to invoke or 'simulate' a Key.Up/.Down on a control on the 2nd window. Is that possible?
Are they sharing an application? If they do, you should be able to call BeginInvoke on the control's event handler
But why to simulate a key press when you can just call a function?
Related
I have a Grid with a Button inside. The button has Flyout menu attached.
I implemented an action which opens the flyout menu when the button is tapped/clicked. This is the default behavior which does not require event writing. I also implemented an action when the grid is tapped/clicked.
The problem is that I do not want the grid to react when I tap/click the button. Based on this fine read, it all makes sense, but in my case, I do not have any code behind to add the e.Handled = true; line to.
Is there any way I could stop event bubbling up the tree using XAML only? Thanks!
While I hate to poach Gusdor's points. There is a built an enumeration property to deal with this types of situations called ClickMode which you can override the default mode for Button of Release and set it at the instance as ClickMode="Press" to get the desired effect and allow it to receive HitTestVisibility individually before any parent does.
Hope this helps, cheers.
I believe you will need to write some code but not the code behind you are trying to avoid.
Create an attached behavior that subscribes to, and handles the
bubbling event.
Attach the behaviour to the element where you want
the event bubbling to stop.
There is a Microsoft article about plugging Behaviours into UWP apps https://blogs.windows.com/buildingapps/2015/11/30/xaml-behaviors-open-source-and-on-uwp/
I need to fire some event when WPF button is pressed (by mouse, keyboard, touchscreen, etc) and to fire event when WPF buttons is unpressed.
How to do this? It should be easy but I can't find how to do this.
You can derive from Button and override the OnIsPressedChanged method and fire a custom event there.
Or you can bind to the ButtonBase.IsPressed property.
Another option is to use DependencyPropertyDescriptor:
var descriptor = DependencyPropertyDescriptor.FromProperty(Button.IsPressedProperty, typeof(Button));
descriptor.AddValueChanged(this.button, new EventHandler(IsPressedChanged));
If you are using MVVM, you can use event triggers to solve your problem. This way, you can still separate your UI requirements from your application logic.
Example 1
Example 2
I know in Silverlight there is a concept of behaviours.
In WPF we have Triggers,
What I am trying to achieve is that when a user has his mouse over a button, I want a command to be fired.
I have a RepeatButton that has its Command Property set, but I want that command (or preferable another command to fire) when the mouse is over that button.Is this possible in WPF.
The Button is in a Control Template.
Thanks
Answer
is there a way to pass input events (primarily mouse, but eventually keyboard input too) that occurs on a HwndHost back to the underlying WPF controls (e.g. a panel) ? i can hook up to WndProc within the HwndHost and recveive the windows messages.
can i manually create a routedevent for a mouse click and send it to the parent so it bubbles up?
and ideas would be appreciated.
thanks
jkersch
If you still require an answer: yes you can. Look at the Microsoft example here: http://msdn.microsoft.com/en-us/library/ms752055.aspx
In that example, the HwndHost derived class 1st creates a 'sub' window and then creates a control (ListBox) in that window. A HwndSourceHook is then added that catches messages (in the example, selection change messages from the ListBox) and uses them in the WPF context.
When using a WPF label as a keyboard shortcut mechanism, is there an event fired for this?
and 2 minutes later I actually find this:
AccessKeyManager.AccessKeyPressed