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

  • SEARCH
  • Home
  • 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 7780457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:54:15+00:00 2026-06-01T18:54:15+00:00

I have a quiz application where there can be up to 3 possible answers.

  • 0

I have a quiz application where there can be up to 3 possible answers. The answers are buttons which have been assigned a style. All the answer buttons have the same click event…

Private Sub butAnswer_Click(ByVal sender as Object, ByVal e as System.Windows.RoutedEventArgs)
    'An Answer has been clicked

    Dim butC as Button
    Dim butS as String = TryCast(sender, Button).Name.ToString()
    'Cycle through all answers and set style
    For x = 1 to 3
        butC = DirectCast(FindName("butAnswer" & x), Button) 
        If butS = "butAnswer" & x.ToString Then
            butC.Style = DirectCast(FindResource("GlassButtonSelected"), Style)
        Else
            butC.Style = DirectCast(FindResource("GlassButton"), Style)
        End If
    Next

End Sub

I now want to expand on this so that if the user clicks a second time on a ‘selected’ answer the style is reverted back to ‘GlassButton’

If butS = "butAnswer" & x.ToString Then
'Check what style the button has
   If 'style is GlassButton' Then
      butC.Style = DirectCast(FindResource("GlassButtonSelected"), Style)
   Else
      butC.Style = DirectCast(FindResource("GlassButton"), Style)
   End If
Else
   butC.Style = DirectCast(FindResource("GlassButton"), Style)
End If

My Question is how do I determine what style the button has?

ADDITIONAL UPDATE

Kent,
Thanks, I’m new to wpf and did not know about all these extra controls…
I’ve now converted my Buttons to ToggleButtons and have a single checked and unchecked event that is used by all ToggleButtons. I’ve amended my style so that the target is ToggleButton and I now just have the one. I’ve got rid of the style I was going to use to indicate a selected answer – basically a change in background colour. My Checked event has…

Private Sub togAnswer_Checked(ByVal sender as Object, ByVal e as System.Windows.RoutedEventArgs)
    'togAnswer was clicked....
    Dim togC as ToggleButton
    Dim togS as String = TryCast(sender, ToggleButton).Name.ToString()
    'Cycle through all answers and set style
    Dim bc = New BrushConverter()

    For x = 1 to 3
        togC = DirectCast(FindName("togAnswer" & x), ToggleButton) 

        If togS = "togAnswer" & x.ToString Then
                            'Set ToggleButton to selected colour
            togC.Background = DirectCast(bc.ConvertFrom("#AAFF8020"), Brush)
        Else    
            'Set other ToggleButtons to unselected colour
            togC.Background = DirectCast(bc.ConvertFrom("#AA000000"), Brush)
        End If
    Next
End Sub

Unfortunately the button colour does not change. Any idea why?

  • 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-01T18:54:17+00:00Added an answer on June 1, 2026 at 6:54 pm

    In short, you’re doing it wrong. You need to identify the behavior (a button that is in one of two states) and distinguish it from the visual manifestation of that behavior. Doing so would lead you to use a ToggleButton and simply alter its appearance based on its IsChecked property.

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

Sidebar

Related Questions

I am working on quiz application . For each question there are multiple answers
I have an application (More likely a quiz app) where i have saved all
I have a .net MVC application which opens up the result of a Quiz
I have create an android quiz application where i loaded all of question from
I'm currently building a quiz application for facebook, which would have a photo uploaded
In my application there are courses which have steps. (A user proceeds though the
We have a quiz application ( which is capable of rendering a question bank
I have a quiz application. Which follows a normal pattern of database development Quiz
I have a simple quiz application and I want display a nice timer /
I have forms which work fine. I have a quiz which works fine. When

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.