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 7927975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:36:16+00:00 2026-06-03T19:36:16+00:00

When a button gets pressed the background ( Rectangle Fill ) of the button

  • 0

When a button gets pressed the background (Rectangle Fill) of the button changes. So the user can see what buttons have been pressed and what not.

Problem:

I use a trigger and a Togglebutton to perform the "IsChecked" to change the background.
But the background change may only happens 1 time.

For example:

Button Background = black –> PRESS –> Button Background = blue

But when i press the button again the Button BackGround changes back to black (since its a ToggleButton).

How can i make sure the background only changes 1 time?

EDIT: The button must remain enabled, because a user gives in a reason when they press the button. Meaning if they pick the wrong reason they are able to change it.

<Style x:Key="ButtonStyleReg" TargetType="{x:Type myClasses:RegButton}">
<Setter Property="Template">
    <Setter.Value>
        <ControlTemplate TargetType="{x:Type ToggleButton}">
            <Grid x:Name="registrationButton">
                <Rectangle Name="rectangleBtn" Fill="#FF89959A" Height="Auto" RadiusY="15" RadiusX="15" Stroke="White" Width="Auto"/>

                <TextBlock x:Name="reason" TextWrapping="Wrap" 
                           Text="{Binding Reason, StringFormat=\{0\}}"
                           HorizontalAlignment="Center" Margin="0,7.5,0,0" Height="Auto" 
                           VerticalAlignment="Top" FontWeight="Bold" >
                </TextBlock>                                                                                   
            </Grid>
            <ControlTemplate.Triggers>
                <Trigger Property="IsFocused" Value="True"/>
                <!--<Trigger Property="IsDefaulted" Value="True"/>-->

                <Trigger Property="IsChecked" Value="True">
                    <Setter TargetName="rectangleBtn" Property="Fill" Value="blue" />
                </Trigger>                                                     
                <Trigger Property="IsEnabled" Value="False"/>
            </ControlTemplate.Triggers>
        </ControlTemplate>

    </Setter.Value>
</Setter>
<Setter Property="FontSize" Value="10.667"/>

Listbox that implements the style:

<ListBox x:Name="lbRegistration" ItemsSource="{Binding RegBtns, ElementName=Window}" Background="{x:Null}" 
            BorderBrush="{x:Null}" Grid.Column="1" 
            ScrollViewer.HorizontalScrollBarVisibility="Hidden" ScrollViewer.VerticalScrollBarVisibility="Disabled" Height="75">
            <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel Orientation="Horizontal"/>
                </ItemsPanelTemplate>
            </ListBox.ItemsPanel>

            <ListBox.ItemTemplate>
                <DataTemplate>
                    <myClasses:RegistrationButton x:Name="RegistrationButton" HorizontalAlignment="Center" Height="71" Width="148" 
                                                  Margin="10,0,5,0" 
                                                  Style="{DynamicResource ButtonStyleRegistration}"
                                                  Click="RegistrationButton_Click"
                                                  Title="{Binding Title}"
                                                  Oorzaak="{Binding Oorzaak}"     

                                                  DuurStilstand="{Binding DuurStilstand, 
                                                        Converter={StaticResource  DateTimeConverter}}"

                                                  BeginStilstand="{Binding BeginStilstand}"/>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

Best Regards,
Pete

  • 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-06-03T19:36:18+00:00Added an answer on June 3, 2026 at 7:36 pm

    Very simple would be if you can access the rectangle from code behind:

    rectangleBtn.Fill = Brushes.Blue;
    

    If you can’t access it – make yourself two styles.
    The one that is the original style, the other one is the Blue Style which shall be applied when the user clicks.

    In the code behind, on event Click=”RegistrationButton_Click”
    Set the Style to the BlueStyle.

    RegistrationButton.Style = this.FindResource("ButtonStyleRegistration") as Style;
    

    Since you always want it blue, this code is enough as it is. It will always make it Blue for you.
    The first time, and any other time.
    That way you achieve your requirement and the style will change only once.
    When the window is loaded, it will load into the original style (the first style).
    So put in your XAML the style “Black” and in the code behind as shown above.

    Then this must be removed:

    <Trigger Property="IsChecked" Value="True"> 
        <Setter TargetName="rectangleBtn" Property="Fill" Value="blue" /> 
    </Trigger>    
    

    Then this:

    <myClasses:RegistrationButton x:Name="RegistrationButton" HorizontalAlignment="Center" Height="71" Width="148"  
    Margin="10,0,5,0"  
    Style="{DynamicResource ButtonStyleRegistration}" 
    Click="RegistrationButton_Click"
    

    Shall be:

    <myClasses:RegistrationButton x:Name="RegistrationButton" HorizontalAlignment="Center" Height="71" Width="148"  
    Margin="10,0,5,0"  
    Style="{DynamicResource ButtonStyleRegBlack}" 
    Click="RegistrationButton_Click"
    

    That is all.

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

Sidebar

Related Questions

I have a problem with asp:button styling. I added following style: .myAspButton { background-image:
I have a tab panel that gets populated with a grid when a button
I need a button-like control that can have a Checked property, so that when
I have 2 radio button with values New & Existing. If user chooses New,
I've got a hidden form field, and when a button gets pressed the value
I see some similar questions here (like JavaScript: Check if CTRL button was pressed
I have a button that I only want enabled when a textfield is not
I have 50 buttons in my project as all are linked, when pressed, to
i have created an image button in my xml <Button android:layout_height=wrap_content android:id=@+id/send android:layout_width=50dip android:background=@drawable/button_back>
As My application supports background task I have an Exit button which will call

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.