0

I am trying to style a button such that when the button is enabled and not mouseover it shows a default image, when button is enabled and mouseover it shows a different image and when it is disabled (regardless of mouseover) it shows a third image.

I tried following this answer but when I run my program I get an error of Provide value on 'System.Windows.Baml2006.TypeConverterMarkupExtension' threw an exception.' Line number '47' and line position '45'. which equates to the line identified by <--- in the snippet below:

        <!-- Edit Button using edit.png (pencil) -->
        <Style x:Key="PencilEditEnabledButtonStyle" TargetType="{x:Type Button}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <Border HorizontalAlignment="Center"
                                VerticalAlignment="Center">
                            <!-- default image -->
                            <Image x:Name="ButtonImage" 
                                   Source="/myLibrary;component/Resources/edit.png"
                                   Height="20"/>
                        </Border>

                        <ControlTemplate.Triggers>
                            <!-- update image on mouseover -->
                            <Trigger Property="IsMouseOver" Value="true">
                                <Setter TargetName="ButtonImage" 
                                        Property="Source"
                                        Value="/myLibrary;component/Resources/edit_mouseover.png" />
                            </Trigger>

                            <!-- update image when button is disabled -->
                            <Trigger Property="IsEnabled" Value="true">
                                <Setter TargetName="ButtonImage"             <---
                                        Property="Source"
                                        Value="/myLibrary;component/Resources/edit_disabled.png" />
                            </Trigger>                                

                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

Is this possible and if so how do I correct the Style.

Community
  • 1
  • 1
BrianKE
  • 4,035
  • 13
  • 65
  • 115

1 Answers1

0

Have you included your "Resources" folder into your project?

  • Click Show All Files icon in the Solution Explorer.
  • Right click your newly appeared "Resources" Folder.
  • Click "Include in project".
  • Rebuild and run.
  • I did verify that all images are available by using each individually. – BrianKE Jan 25 '17 at 12:20
  • I tested your code by changing only the Source for the images and I was able to achieve your behavior successfully. Can you create a sample and upload it so I can take a look at the issue? **Also**, here you should probably change the Value to false: – Tacho Jelev Jan 26 '17 at 06:50
  • It was the Value="true" that I had to change to make this work, stupid mistake. If you want to make this an answer, I will mark it as accepted. – BrianKE Jan 27 '17 at 13:28