0

I have tried to set the parameters for this using style="flat.etc.." and I have also tried to set parameters globally. From what I can find via Google everything seems to be targetted towards older versions of Visual studio perhaps as suggestions seems to not work and is some what outdated.

Here is my XAML at the moment:

<Window x:Class="EmoticonPaste.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:EmoticonPaste"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
    </Window.Resources>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="109*"/>
            <ColumnDefinition Width="408*"/>
        </Grid.ColumnDefinitions>
        <Button Content="" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="72" Height="72" BorderThickness="0" Click="Button_Click_1" Grid.ColumnSpan="2">
            <Button.Background>
                <ImageBrush ImageSource="C:/Users/Jamie/Documents/Visual Studio 2017/Projects/EmoticonPaste/EmoticonPaste/img/1f600.png"/>
            </Button.Background>
        </Button>
        <Button x:Name="button" Content="" Grid.Column="1" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Width="72" Click="button_Click_2" Height="72" Padding="1" BorderThickness="0">
            <Button.Background>
                <ImageBrush ImageSource="C:/Users/Jamie/Documents/Visual Studio 2017/Projects/EmoticonPaste/EmoticonPaste/img/1f601.png"/>
            </Button.Background>
        </Button>
    </Grid>
</Window>

Here is what I want to stop happening, disable the hover effect completely so when it hovers over the button the emoticon (set as Brush -> Image but not important I don't think?) stays there, it remains static and there is no highlighting of the button at all, what can I add to my XAML to achieve this? It would be good if I could do it for all buttons in the form as well (globally)

enter image description here

stuartd
  • 70,509
  • 14
  • 132
  • 163
  • 1
    Your code should work. It looks like you added some styles in App.xaml. – Valerii Sep 05 '17 at 20:52
  • Why should it work can you be more specific please? Thanks in advance! –  Sep 05 '17 at 20:56
  • 1
    _"From what I can find via Google everything seems to be targetted towards older versions of Visual studio perhaps as suggestions seems to not work"_ -- they should work. WPF hasn't changed appreciably in over a decade. What suggestions have you tried? Why didn't they work? The short version: you need to edit the template (which will create a new copy of the template in your XAML) and remove the hover effect from the template the designer inserts into your XAML. Alternatively just override the trigger behavior with your own style for the button. – Peter Duniho Sep 05 '17 at 20:57
  • They did not work because the button remained the same. E.g. I tried:style="flat.etc..." or something like that (I can't find the link now) but the emphases was on the button being flat to disable it. The program ran fine, but the behaviour still remained. This is why it did not work. The rest of the suggestions did not fit in with my XAML code so I was unsure where to start / how to embed into my existing code. How do I do this exactly in my existing code?:"remove the hover effect from the template the designer inserts into your XAML" How do I override a trigger behaviour, what is it exactly? –  Sep 05 '17 at 21:01
  • 1
    You do not change default behavior in your code, but in provided gif on mouse hover background of the button is changed. It is not default button behavior. It means that it was changed somewhere. If you add styles or merged dictionaries in App.xaml this styles and styles from merged dictionaries would be applied to whole application. Please share your App.xaml too. – Valerii Sep 05 '17 at 21:16
  • 1
    @Valerii Sure that's the default behavior when you just set the Button's Background. The "hover background" element covers the "default" background. You have to change the Button's Template to avoid this. Try it yourself. – Clemens Sep 05 '17 at 21:23
  • 1
    Thanks to @Clemens for finding the duplicate. I'd looked but used the wrong keywords and didn't find anything quite right. Having not found a duplicate myself, I'd written up an answer here, but seeing the marked duplicate I agree the other question does address this. However, IMHO the answers there don't quite cover what a person really needs to understand to deal with this generally. So you may find [my answer](https://stackoverflow.com/a/46063635) which I just posted there (instead of here as I'd meant to) helpful as well. – Peter Duniho Sep 05 '17 at 21:32
  • I shall be honest, I am trying here but completely lost now. From what I gather you want me to make the button remain in its behaviour of the hover property which seems counter to what I am asking? Not to sure quite what you mean otherwise? Also just to clarify as someone put this was a duplicate and deleted their comment, of a previous question, if it is please point me to the question then I will try everything on that thread as I have gone through quite a few questions before posting this one. –  Sep 05 '17 at 21:33
  • I can't see a link for a duplicate? –  Sep 05 '17 at 21:34
  • 1
    If you reload this page, you'll find the link to the marked duplicate in a banner at the top of your question. And I agree with the assessment that your question is effectively a duplicate of that one. I hope that you'll be able to use the information there (whether my answer or one of the others) to solve your problem, but if not, then you can post a new question that shows what you've tried from that duplicate and explain what you're still having trouble with. – Peter Duniho Sep 05 '17 at 21:34
  • Ok thanks, apologies, I have not come across this question even with searching, perhaps it needs better keywords or tags? –  Sep 05 '17 at 21:35
  • 1
    I'm pretty good at searching and even I didn't find the duplicate. Because the marked duplicate doesn't actually mention _hover_ per se, it is trickier to find. It's just a matter of guessing what keywords _will_ find it. Fortunately, the Stack Overflow community can step in and help find duplicates for you, if you've made an honest effort to and still can't find the answer (as was the case here). :) – Peter Duniho Sep 05 '17 at 21:37
  • 1
    Finally, one last tip: if you post a comment and want to direct it at some specific person who has already commented, you can include their user-name preceded with an `@` character, and that person will get a notification that there's a comment for them. – Peter Duniho Sep 05 '17 at 21:38
  • One last question, in the duplicate question is this reffering to edit in the app.xaml file or mainwindow.xaml? –  Sep 05 '17 at 21:39
  • Your comments have been noted @PeterDuniho –  Sep 05 '17 at 21:39
  • Sorry. I was wrong. Maybe you will get what you need if you set Content of the button equal to image instead of setting Background. – Valerii Sep 05 '17 at 21:40
  • _"is this reffering to edit in the app.xaml file or mainwindow.xaml"_ -- you can edit the button style or template in either place. If in `App.xaml`, then the change will affect the entire program. If in `MainWindow.xaml`, it will affect only the buttons in that window. Of course, if you simply declare the style and apply it individually (instead of making it the default) then it will affect only those buttons you apply it to; you'll only be _able_ to apply it to buttons in `MainWindow`, if that's where you put the style. – Peter Duniho Sep 05 '17 at 21:51

0 Answers0