IsMouseOver behavior
Hey,
Im trying to get a "hover" effect on my button and cant seem to figure out what the problem is with what im doing..
So I have a button and a control template which should convert the button from a round shape to some rectangluar shape when triggered on "IsMouseOver" trigger:
This is the control template:
This is the usage:
I get very weird behaviour.. i dont get a hover effect without clicking the mouse..
If i hover over the button nothing happens, but if i left click and hold and then hover over the mouse, i get the desired behavior.
I've tested with XamlToy that you have on the site, and it seems as though the code is correct since i get the behavior i expect, so there is probably something wrong with my integration.. could you maybe try and guide me to might cause this?
I would really appreciate your help here :)
Thanks a lot in advance!
Im trying to get a "hover" effect on my button and cant seem to figure out what the problem is with what im doing..
So I have a button and a control template which should convert the button from a round shape to some rectangluar shape when triggered on "IsMouseOver" trigger:
This is the control template:
Code: Select all
<!-- Define reusable ControlTemplate for round buttons -->
<ControlTemplate x:Key="test" TargetType="Button">
<Border x:Name="border" Background="{TemplateBinding Background}" CornerRadius="80" Width="160" Height="160">
<!-- Using ContentPresenter to display button content (TextBlock) -->
<ContentPresenter x:Name="contentPresenter" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
<!-- Triggers to change background color and content visibility on Button events -->
<ControlTemplate.Triggers>
<!-- Change background color when button is pressed -->
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="border" Property="Width" Value="470"/>
<Setter TargetName="border" Property="Height" Value="160"/>
<Setter TargetName="border" Property="CornerRadius" Value="80"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>Code: Select all
<Button Height="Auto" Width="Auto" Canvas.Left="1600" Canvas.Top="800" Background="#4DEBD7F8" Template="{StaticResource test}">
<Image Source="/ScreenResources_HomeScreen;component/logo.jpeg" Width="160" Height="160"/>
</Button>
If i hover over the button nothing happens, but if i left click and hold and then hover over the mouse, i get the desired behavior.
I've tested with XamlToy that you have on the site, and it seems as though the code is correct since i get the behavior i expect, so there is probably something wrong with my integration.. could you maybe try and guide me to might cause this?
I would really appreciate your help here :)
Thanks a lot in advance!
-
-
sfernandez
Site Admin
- Posts: 3363
- Joined:
Re: IsMouseOver behavior
Hi,
I guess you are already sending all the mouse events, including MouseMove, to the View:
Did you enable the touch emulation in the View? Because when touch is emulated, MouseMove events are ignored if no "finger" (left mouse button) is pressed.
I guess you are already sending all the mouse events, including MouseMove, to the View:
Code: Select all
NS_INTERFACE IView: public Interface
{
/// Notifies that a mouse button was pressed. Origin is in the upper-left corner.
/// Returns true if event was handled
virtual bool MouseButtonDown(int x, int y, MouseButton button) = 0;
/// Notifies that a mouse button was released. Origin is in the upper-left corner.
/// Returns true if event was handled
virtual bool MouseButtonUp(int x, int y, MouseButton button) = 0;
/// Notifies that a mouse button was double clicked. Origin is in the upper-left corner.
/// When a double click happens the following sequence of events are expected:
/// - MouseButtonDown (first click)
/// - MouseButtonUp
/// - MouseDoubleClick (second click)
/// - MouseButtonUp
/// See https://docs.microsoft.com/en-us/windows/win32/learnwin32/mouse-clicks#double-clicks
/// Returns true if event was handled
virtual bool MouseDoubleClick(int x, int y, MouseButton button) = 0;
/// Notifies that mouse was moved. Origin is in the upper-left corner.
/// Returns true if event was handled
virtual bool MouseMove(int x, int y) = 0;
/// Notifies that mouse vertical wheel was rotated. Origin is in the upper-left corner
/// The parameter wheelRotation indicates the distance the wheel is rotated, expressed in
/// multiples or divisions of 120 (is the default value for 3 lines of scrolling). A positive
/// value indicates that the wheel was rotated forward, away from the user; a negative value
/// indicates that the wheel was rotated backward, toward the user.
/// Returns true if event was handled
virtual bool MouseWheel(int x, int y, int wheelRotation) = 0;
/// Notifies that mouse horizontal wheel was rotated. Origin is in the upper-left corner
/// The parameter wheelRotation indicates the distance the wheel is rotated, expressed in
/// multiples or divisions of 120 (is the default value for 3 lines of scrolling). A positive
/// value indicates that the wheel was rotated to the right; a negative value indicates that
/// the wheel was rotated to the left.
/// Returns true if event was handled
virtual bool MouseHWheel(int x, int y, int wheelRotation) = 0;
...
};Code: Select all
virtual void SetEmulateTouch(bool emulate) = 0;Re: IsMouseOver behavior
Yes!!!! That fixed it, it was the emulator. thanks a lot!
Who is online
Users browsing this forum: No registered users and 3 guests