- Ismouseover wpf триггер не работает
- Answered by:
- Question
- Answers
- All replies
- IsMouseOver not triggering
- 1 Answer 1
- UIElement. Is Mouse Over Свойство
- Определение
- Значение свойства
- Реализации
- Примеры
- Комментарии
- Event for MouseOver action in WPF
- 4 Answers 4
- Not the answer you’re looking for? Browse other questions tagged wpf or ask your own question.
- Linked
- Related
- Hot Network Questions
- Subscribe to RSS
- WPF — How to write a trigger for mouse over of grid?
- 3 Answers 3
Ismouseover wpf триггер не работает
This forum has migrated to Microsoft Q&A. Visit Microsoft Q&A to post new questions.
Answered by:
Question
i need your help to fix simple issue.
i want to customize my WPF button i used this code
The color on mouseOver do not change .
Why ? can you help me ?
Please i do not want to use Button.Template
Answers
>>Please i do not want to use Button.Template
I am afraid you must override the default template of the Button to be able to change the colour of it when the mouse pointer is over it. There is no other way to do it.
Just right-click the Button in design mode in Visual Studio 2012 or 2013, select the «Edit template»->»Edit a copy» option to generate the XAML of the default template and then change the Color property of the SolidColorBrush resource with the x:Key «Button.MouseOver.Background» to change the background:
To change the foreground, you could add a Setter to the IsMouseOver trigger of the default ControlTemplate:
Here is the complete generated and modifed XAML and a test Button that uses the generated style:
All replies
>>Please i do not want to use Button.Template
I am afraid you must override the default template of the Button to be able to change the colour of it when the mouse pointer is over it. There is no other way to do it.
Just right-click the Button in design mode in Visual Studio 2012 or 2013, select the «Edit template»->»Edit a copy» option to generate the XAML of the default template and then change the Color property of the SolidColorBrush resource with the x:Key «Button.MouseOver.Background» to change the background:
To change the foreground, you could add a Setter to the IsMouseOver trigger of the default ControlTemplate:
Here is the complete generated and modifed XAML and a test Button that uses the generated style:
It’s a bit complicated, I do not want to use styles and I want just to put it down the Button style and not in resources because.
1 — I have a DataTriggers that binds with another button
something like
2 — When I use a template, I can not change its value in the C # code.
Is there a way around this?
You were orignally asking about how to change the mouse over color of the Button and I gave you a detailed description and a sample about how to do this.
Now you are asking something about DataTriggers? I don’t understand what you mean but as already mentioned you must override the default style of the Button in order to be able to change the mouse over colour. If you already have a style applied to the Button, then put the markup for the generated template in there as the setter for the Template property too.
Once again you must set either the Style or Template property of the Button to be able to change the colour unless you define a style in your window or App.xaml that will apply to all Button elements in the window or application respectively.
And of course you can change the Content property of the Button in code or in XAML when you use the default template. Try with my sample markup above and you will see that it works. If it doesn’t work for you, your template is wrong.
«It’s a bit complicated» is certainly not enough information for anyone to be able to help you. Please post all relevant code and markup if you need any further help and explain your issue in detail.
But please don’t ask several questions in the same thread. Remember that a new question deserves a new thread.
Источник
IsMouseOver not triggering
This question is related to another question that I just barely asked on SO as well.
I have a Canvas with both a Path and a TextBlock in it.
The IsMouseOver property of the canvas triggers the path style as I expect it to when the mouse pointer is over the drawn path. However, when the mouse pointer is over the textblock (which is positioned right smack in the middle of the drawn path) then the path style does not trigger as I expect it to.
Why does it not trigger? The textblock resides within the canvas, so technically speaking isn’t the mouse pointer over the canvas as well?
Thanks in advance for any help on this.
1 Answer 1
The reason is that, you set the Trigger’s Property to Canvas.IsMouseOver, so it will fire when the Canvas is Mouser Over. But as you set the Trigger in the Path’s Style, this will limited within the area of the Path.
I know the IsMouseOver is a Property, but i want to use MouseEnter as an example. MouseEnter is a Routed Event, so when the mouse is hover the TextBlock, it will fire as Routed Event, the TextBlock’s MouseEnter Event will fire, and maybe the TextBlock’s IsMouseOver became true, not the Path and the Canvas. Because now the TextBlock’s ZIndex is the highest.
So, what we need to do is let the TextBlock’s IsMouseOver don’t change when it get hovered.
We can set the TextBlock’s IsHitTestVisible=»False»;
And the Code can be like this: I have tested this code, it works!
Источник
UIElement. Is Mouse Over Свойство
Определение
Некоторые сведения относятся к предварительной версии продукта, в которую до выпуска могут быть внесены существенные изменения. Майкрософт не предоставляет никаких гарантий, явных или подразумеваемых, относительно приведенных здесь сведений.
Получает значение, указывающее, находится ли указатель мыши над данным элементом (включая дочерние элементы в визуальном дереве). Это свойство зависимостей.
Значение свойства
Значение true , если указатель мыши находится над элементом или его дочерними элементами; в противном случае — значение false . Значение по умолчанию — false .
Реализации
Примеры
Следующий пример ссылается на это свойство как на тип свойства Trigger , часть блока. Если указатель мыши находится над элементом управления, то текст элемента управления становится синим, а курсор — рукой.
Комментарии
Как правило, элементы управления являются составными, так что различные элементы внутри элемента управления (визуальное дерево) будут сообщать о состоянии мыши для содержащего его элемента управления. Например, ListBox элемент управления «стиль» будет сообщать, IsMouseOver как true если бы мышь находилась в любом месте над его геометрической фигурой, включая любые ListBoxItem .
Хотя аналогичное событие «Исмаусеоверчанжед» не существует, выполняется несколько аналогичных событий. Например, можно выполнять обработку MouseEnter , MouseMove и IsMouseDirectlyOverChanged .
Если этот элемент захватывает мышь, это свойство сохраняется true до тех пор, пока захват мыши не будет потерян и указатель мыши покидает границы элемента.
Некоторые элементы управления намеренно захватывают мышь над определенными действиями, которые не связаны непосредственно с мышью. Это может привести к тому IsMouseOver , что true мышь не перемещалась.
Источник
Event for MouseOver action in WPF
I want to handle mouse over and mouse out events for a grid. Does WPF have events for this. Note: I dont want to use IsMouseOver property in my style. i have used MouseEnter and MouseLeave method but without much success.
4 Answers 4
You can use EventTriggers to capture MouseEnter and MouseLeave events in XAML.
Here is a simple example that changes the background of a StackPanel in a Grid:
A WPF Grid control supports both the MouseEnter and MouseLeave events. You should be able to hook up event handlers for both.
More simple : You can implement the two events PointerMoved and PointerExited. It worked for me.
MouseEnter and MouseLeave events may be handled , you can check your code set e.handled = false;
Not the answer you’re looking for? Browse other questions tagged wpf or ask your own question.
Linked
Related
Hot Network Questions
Subscribe to RSS
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2021.10.18.40487
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.
Источник
WPF — How to write a trigger for mouse over of grid?
I see that Button object has a IsMouseOVer property.
But how do create an effect for the mouse over of a grid or other element that does not have IsMouseOver??
Edit: i figured it out. I was using the wrong method for setting the trigger.
3 Answers 3
I realize that I am responding to a dead thread but since I came across it, and since the thread is not answered, I am going to answer it.
The WPF Grid has an «IsMouseOver» property.
I think this question was asked because the «IsMouseOver» property only changes if the mouse is over a «hit-testable» control (ie a Button, or ComboBox) within the Grid itself.
Therefore, it may appear that the «IsMouseOver» property doesn’t work (especially if you are using it in a trigger to set the Grid’s Visible property).
The above Grid and it’s contents will be displayed in half opacity. You will notice that the opacity will not be set to full if you hover over the first column (which doesn’t contain anything); however the opacity will be set to full if you hover over the button in the second column. This is because the first column, with nothing in it, is not hit-testable; whereas, the button within the second column is hit-testable and so the event is triggered.
If you want the Grid’s IsMouseOver property to detect when the mouse is anywhere over the Grid itself all you have to do is set the Background property of the Grid to something that is not Null (set it to Transparent for example). Setting the Background property will make the Grid «hit-testable».
Источник