Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6679731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:23:34+00:00 2026-05-26T04:23:34+00:00

I have a chromeless button in a WPF application that uses the XAML style

  • 0

I have a chromeless button in a WPF application that uses the XAML style below:
However, there are 2 things that I’m trying to do with it.

  1. I want the displayed image to be one of two images, depending on a binding property from the datacontext of the template the button is in. The property is a boolean. Show one image if False, the other if True.
  2. I would like the image shown to change when the mouse hovers over the button and to be the image that would be shown when above bound property is True.

I’ve tried several things, but nothing really seems to work. I tried a converter with the bound value like this:

        <x:ArrayExtension x:Key="ThumbsDown" Type="BitmapImage">
            <BitmapImage UriSource="/Elpis;component/Images/thumbDown.png" />
            <BitmapImage UriSource="/Elpis;component/Images/thumbBan.png" />
        </x:ArrayExtension>

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var data = (object[])parameter;

            if (data.Length != 2 || value == null || value.GetType() != typeof(bool))
                return data[0];

            if(!((bool)value))
                return data[0];
            else
                return data[1];
        }

<Button Name="btnThumbDown" Grid.Column="1" Style="{StaticResource NoChromeButton}" 
                                            VerticalAlignment="Center" 
                                            HorizontalAlignment="Center" 
                                            Background="Transparent"
                                            Click="btnThumbDown_Click">
                                <Image  Width="32" Height="32" Margin="2" 
                                        Source="{Binding Banned, 
                                                Converter={StaticResource binaryChooser}, 
                                                ConverterParameter={StaticResource ThumbsDown}}"/>
                            </Button>

But this causes 2 problems. Nothing I do for the hover image works anymore and the designer throws an exception.

The opacity trigger from below can go, as I really just want the hover now.

Any thoughts on how to make this properly work?

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Style x:Key="NoChromeButton" TargetType="{x:Type ButtonBase}">
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="BorderThickness" Value="1"/>
        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
        <Setter Property="HorizontalContentAlignment" Value="Center"/>
        <Setter Property="VerticalContentAlignment" Value="Center"/>
        <Setter Property="Padding" Value="1"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ButtonBase}">
                    <Grid x:Name="Chrome" Background="{TemplateBinding Background}" SnapsToDevicePixels="true">
                        <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                                          Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" 
                                          SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
                                          VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Opacity" Value="0.75"/>
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="False">
                            <Setter Property="Opacity" Value="1.0"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:23:34+00:00Added an answer on May 26, 2026 at 4:23 am

    I would solve this by adding an Image control to the ControlTemplate of the button, and then create a MultiDataTrigger with one condition for IsMouseOver and one condition for the boolean property that you want to bind to. The trigger then sets the source of the image when active.

    Below is a style that accomplishes this. I’ve assumed that the button has a DataContext which contains the boolean property, and that the boolean property is called MyBoolean.

    <Style x:Key="NoChromeButton" TargetType="{x:Type ButtonBase}">
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="BorderThickness" Value="1"/>
        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
        <Setter Property="HorizontalContentAlignment" Value="Center"/>
        <Setter Property="VerticalContentAlignment" Value="Center"/>
        <Setter Property="Padding" Value="1"/>
        <Setter Property="Template">
            <Setter.Value>
                <!-- I assume that the button has a DataContext with a boolean property called MyBoolean -->
                <ControlTemplate TargetType="{x:Type ButtonBase}">
                    <Grid x:Name="Chrome" Background="{TemplateBinding Background}" SnapsToDevicePixels="true">
                        <!-- Not sure about what the button should look like, so I made it an image to the left
                                and the button's content to the right -->
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="auto" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <Image x:Name="ButtonImage" Grid.Column="0" Source="/Elpis;component/Images/thumbBan.png" />
                        <ContentPresenter Grid.Column="1"
                            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                                        Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" 
                                        SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
                                        VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                    </Grid>
                <ControlTemplate.Triggers>
                    <!-- As I understand it, ThumbBan should be shown when IsMouseOver == True OR the bound boolean is true,
                            so if you invert that you could say that the ThumbDown image should be shown
                            when IsMouseOver == false AND the bound boolean is false, which is what this trigger does -->
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding IsMouseOver, ElementName=Chrome}" Value="False" />
                                <Condition Binding="{Binding MyBoolean}" Value="False" />
                            </MultiDataTrigger.Conditions>
                            <MultiDataTrigger.Setters>
                                <Setter TargetName="ButtonImage" Property="Source" Value="/Elpis;component/Images/thumbDown.png" />
                            </MultiDataTrigger.Setters>
                        </MultiDataTrigger>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="Opacity" Value="0.75"/>
                    </Trigger>
                    <!-- The trigger that sets opacity to 1 for IsMouseOver false is not needed, since 1 is the 
                            default and will be the opacity as long as the trigger above is not active -->
                </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    

    You might have to switch which image should be displayed when the trigger is active, if I misunderstod the requirements.

    The trick here is to use a MultiDataTrigger so that the two conditions you mention can be combined. Usually you would probably use a Trigger instead of a DataTrigger when binding to IsMouseOver of a control. But since you need a DataTrigger for the boolean property the IsMouseOver binding can be written as a DataTrigger by using the ElementName property of the binding. By doing that you make is possible to use a MultiDataTrigger to combine the two.

    UPDATE:

    To add support for customizing the images used, and also which property to bind to, for each button instance I would subclass the Button class and add a couple of DependencyProperties.

    public class ImageButton : Button
    {
        public static readonly DependencyProperty ActiveImageUriProperty =
            DependencyProperty.RegisterAttached("ActiveImageUri", typeof(Uri), typeof(ImageButton),
                new PropertyMetadata(null));
    
        public static readonly DependencyProperty InactiveImageUriProperty =
            DependencyProperty.RegisterAttached("InactiveImageUri", typeof(Uri), typeof(ImageButton),
                new PropertyMetadata(null));
    
        public static readonly DependencyProperty IsActiveProperty =
            DependencyProperty.RegisterAttached("IsActive", typeof(bool), typeof(ImageButton),
                new PropertyMetadata(false));
    
        public Uri ActiveImageUri
        {
            get { return (Uri)GetValue(ActiveImageUriProperty); }
            set { SetValue(ActiveImageUriProperty, value); }
        }
    
        public Uri InactiveImageUri
        {
            get { return (Uri)GetValue(InactiveImageUriProperty); }
            set { SetValue(InactiveImageUriProperty, value); }
        }
    
        public bool IsActive
        {
            get { return (bool)GetValue(IsActiveProperty); }
            set { SetValue(IsActiveProperty, value); }
        }
    }
    

    This class could then be used in the following way:

    <SomeNamespace:ImageButton Height="23" Width="100" Content="Button 1"
        ActiveImageUri="/Elpis;component/Images/thumbBan.png"
        InactiveImageUri="/Elpis;component/Images/thumbDown.png"
        IsActive="{Binding MyBoolean}" />
    
    <SomeNamespace:ImageButton Height="23" Width="100" Content="Button 2"
        ActiveImageUri="/Elpis;component/Images/someOtherImage.png"
        InactiveImageUri="/Elpis;component/Images/yetAnotherImage.png"
        IsActive="{Binding SomeOtherBooleanProperty}" />
    

    The control template could then be modified to look like this:

    <Style TargetType="SomeNamespace:ImageButton">
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" />
        <Setter Property="HorizontalContentAlignment" Value="Center" />
        <Setter Property="VerticalContentAlignment" Value="Center" />
        <Setter Property="Padding" Value="1" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type SomeNamespace:ImageButton}">
                    <Grid x:Name="Chrome" Background="{TemplateBinding Background}" SnapsToDevicePixels="true">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="auto" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <Image x:Name="ButtonImage" Grid.Column="0"
                            Source="{Binding ActiveImageUri, RelativeSource={RelativeSource TemplatedParent}}" />
                        <ContentPresenter Grid.Column="1"
                            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                            Margin="{TemplateBinding Padding}" RecognizesAccessKey="True"
                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                            VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
                    </Grid>
                    <ControlTemplate.Triggers>
                        <!-- The "active" image should be shown when IsMouseOver == True OR the bound boolean is true,
                            so if you invert that you could say that the "inactive" image should be shown
                            when IsMouseOver == false AND the bound boolean is false, which is what this trigger does -->
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsMouseOver" Value="False" />
                                <Condition Property="IsActive" Value="False" />
                            </MultiTrigger.Conditions>
                            <MultiTrigger.Setters>
                                <Setter TargetName="ButtonImage" Property="Source"
                                    Value="{Binding InactiveImageUri, RelativeSource={RelativeSource TemplatedParent}}" />
                            </MultiTrigger.Setters>
                        </MultiTrigger>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Opacity" Value="0.75" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    

    The major changes here is that the source for the image is set to the values of the dependency properties instead of hard coded URIs, and that the MultiDataTrigger has been changed into a MultiTrigger which binds to the dependency properties. Previously the path to the boolean property was also hard coded, but now that is configurable by changing the binding for the IsActive property when creating the button, as shown in the example above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get the youtube as3 chromeless player to work. I have followed
Have a LinqtoSql query that I now want to precompile. var unorderedc = from
Have some data in a sybase image type column that I want to use
have a table that dynamically generates text boxes in run time. I want to
Recently I have made a simple flash application that utilizes a webcam feed and
In my button.xul file I have this: <script type=application/x-javascript src=chrome://mf_unblocker/content/button.js/> <toolbarbutton id=custom-button-1 label=Custom tooltiptext=MAFIAAFire:
I have chromeless application with some privileged JavaScript code interacting with the system.Now I
A player: http://www.yvoschaap.com/videowall/ How can you customise the above Chromeless Youtube to have Play/Stop/Pause
Have you ever seen any of there error messages? -- SQL Server 2000 Could
Have you used VS.NET Architect Edition's Application and System diagrams to start designing a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.