I have an problem. I have tabitems and if these items have images in the in the header, the window_loaded event is triggered before the window become visible. If the tabitems are just plain old tabitems, the window is visible before the loaded event. Does anyone know why is that happening?
As described here, I believe that you really should be using Window.ContentRendered instead of Window.Loaded
#StillLearnin thanks for pointing to the right direction.
Instead of using Window_Loaded event I used Window_ContentRendered
Related
I have a problem in my wpf project. I have a webbrowser control. What I want is to know whether anybody has clicked on the webrowser control. I used the mousedown event. But to my surprise it is not firing the event. In the webbrowser control I find that only Navigated and Navigating events are fired. Please let me know how can I get mousedown event? Thanks for your time.
Mouse events are not supported by the WebBrowser control. Please refer to the following (duplicate) question for more information about how you could solve this.
WPF WebBrowser Mouse Events not working as expected
MACMAN, add event handler manually, like this:
public MainWindow()
{
InitializeComponent();
AddHandler(FrameworkElement.MouseDownEvent, new MouseButtonEventHandler(WebBrowser_MouseDown), true);
ps: See this topic: https://social.msdn.microsoft.com/Forums/en-US/61807025-d4c4-41e0-b648-b11183065009/mousedown-event-not-working-wpf?forum=wpf
I got the solution by injecting javascript that adds a html mousedown event to the website. The javascirpt in turn invokes a wpf function that is written into a class using ComVisible[true].
http://sekhartechblog.blogspot.in/2012/04/webbrowser-javascript-communication-in.html
I have a custom control which inherits from Control and I'm trying to trigger MouseLeftButtonDown using Touch on WPF platform.The event MouseLeftButtonDown does not fire while touch the window but its works fine when use mouse device. I have tried the related PreviewMouseLeftButtonDown event also nothing happens while touch the window.
Please suggest me the solution.
Regards,
Jeyasri M
Already in another post
WPF combining MouseDown and TouchDown to same event
Anyway have a look to this, maybe can help...
https://blogs.msdn.microsoft.com/llobo/2009/12/07/wpf-touch-basics/
https://blogs.msdn.microsoft.com/jaimer/2009/11/04/introduction-to-wpf-4-multitouch/
I am using Visual Studio 2012. I have added reference to System.Windows.Forms. But I cannot find Form.Shown event handler in the properties-eventhandler window.
Please help me.
Is there any alternative for the same?
When you are using WPF, you can not use WinForms. Those are not the same. You must use the Events from the Window class in WPF.
I assume you use WPF since the WPF tag is there.
For a WPF window I would use one of the following events:
Activated Occurs when a window becomes the foreground window.
GotFocus Occurs when this element gets logical focus.
Loaded Occurs when the element is laid out, rendered, and ready for interaction.
StateChanged Check if WindowState == WindowState.Normal
The WPF equivalent handlers you are possibly looking for are Loaded() and/or Activated(). You might also look at SizeChanged()
I have the following situation (simplified): In a WinForms Form, I have a GroupBox. Inside it are some UserControl_A objects, each of which contains several UserControl_B objects (both being derived from UserControl, of course).
I have a ContextMenuStrip for the GroupBox which is working fine with each right click, regardless whether on any UserControl_A/B object or the GroupBox background itself.
But I also need to process left clicks. Handling the Click and MouseClick events of the GroupBox is working, but only on the background. As soon as the pointer is inside a UserControl_A or UserControl_B object, nothing happens. I have tried to handle the Click and MouseClick events of both UserControl classes, but the handlers are never called at all.
Any hints what is going wrong here? Or how one can debug such an event handling problem?
Thank you very much in advance,
Stefan
Addition: I have now made a completely new, stripped-down project to explore the situation, and everything works fine. So how can I detect what's going wrong with my real project?
You have to add your UserControls as child control to GroupBox:
groupBox.Controls.Add(yourUserControl); // correct way
in this type, right click works for all child of your parent control (GroupBox).
form.Controls.Add(groupBox);
form.Controls.Add(yourUserControl); // wrong way
you put Mouse event in UserControl_A (i think it's class inherits Control)
the event will trigger when Mouse (over, down, etc.......) on that(UserControl)
when you on (your GroupBox ) the events blong to the groupBox
I am trying to create a mouse hover state which it changes its opacity when a mouse is over the stack panel.
I have created the state, and created a mouse_enter event for the stack panel, and on the code behind cs file, I have the following code on Mouse_Enter event.
MouseOver.Begin();
Where MouseOver is the StoryBoard's name, but when my mouse is hovering over the stack panel or even click on the stack panel, nothing happened, what am I missing?
Thanks
PlayKid
I figured out myself.
With this code:
VisualStateManager.GoToState
Thanks everyone.
Are you sure that the event is fired (you have wired up the event properly) ? Try checking using a message box or something. (System.Windows.MessageBox.Show())
Are you sure the storyboard works well in other situations (tried it on page load or something?)
If both these work, please explain how you went about adding the event handler.
In my experience, hooking up a Mouse_Enter event to the panel doesn't work because the content inside the panel ends up stealing the event. My usual solution is to set up a transparent target that covers the area that I want mouse events for and keep that item on the top of the visual tree. So the XAML looks something like:
<StackPanel x:Name="ContentPanel" SizeChanged="ContentPanelSizeChanged" >
< /*Some content here */ >
</StackPanel>
<Canvas x:Name="HitTarget" Mouse_Enter="HitTargetMouseEnter" />
And then the ContentPanelSizeChanged handler sets the size of the HitTarget Canvas to be the actual (rendered) size of the StackPanel. Same thing works for MouseButtonDown events and I would presume it works for MouseWheel events as well. I'd recommend trying Senthil's troubleshooting suggestions, but if you can't get the event to fire at all (which I would presume is the problem), give this a try.