Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. WPF
  4. RadioButton DataBinding, without code-behind

RadioButton DataBinding, without code-behind

Scheduled Pinned Locked Moved WPF
wpfquestioncsharpwcf
7 Posts 4 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hhrafn
    wrote on last edited by
    #1

    Hi, I'm trying to do DataBinding in XAML woutout any coudebehind. However I can't find any of the nice Binding features found on most other WPF controls. What is the most current and prefered way to do databinding on RadioButtons ?

    M 1 Reply Last reply
    0
    • H hhrafn

      Hi, I'm trying to do DataBinding in XAML woutout any coudebehind. However I can't find any of the nice Binding features found on most other WPF controls. What is the most current and prefered way to do databinding on RadioButtons ?

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      hhrafn wrote:

      I can't find any of the nice Binding features found on most other WPF controls

      Which properties of the RadioButton control are you trying to bind to that are missing "the nice Binding features"?

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      H 1 Reply Last reply
      0
      • M Mark Salsbery

        hhrafn wrote:

        I can't find any of the nice Binding features found on most other WPF controls

        Which properties of the RadioButton control are you trying to bind to that are missing "the nice Binding features"?

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        H Offline
        H Offline
        hhrafn
        wrote on last edited by
        #3

        well, I'd like to use the radio buttons like this: (in theory at least) <RadioButtons ItemsSource="{Binding Colors}" /> Then picking up the selected item through a selectedItem binding (?) Basically my problem is that I need it to be MVVM (no codebehind) and this radio button list will also be dynamic (changeable).

        G M A 3 Replies Last reply
        0
        • H hhrafn

          well, I'd like to use the radio buttons like this: (in theory at least) <RadioButtons ItemsSource="{Binding Colors}" /> Then picking up the selected item through a selectedItem binding (?) Basically my problem is that I need it to be MVVM (no codebehind) and this radio button list will also be dynamic (changeable).

          G Offline
          G Offline
          Gideon Engelberth
          wrote on last edited by
          #4

          Well, a RadioButton is not an items control, and I have never heard of a "RadioButtons" control. You might try using an ListBox to allow you to bind the ItemsSource and make a RadioButton in the ItemTemplate. The tricky part will be binding the IsChecked of the RadioButton to the IsSelected on the ListBoxItem.

          1 Reply Last reply
          0
          • H hhrafn

            well, I'd like to use the radio buttons like this: (in theory at least) <RadioButtons ItemsSource="{Binding Colors}" /> Then picking up the selected item through a selectedItem binding (?) Basically my problem is that I need it to be MVVM (no codebehind) and this radio button list will also be dynamic (changeable).

            M Offline
            M Offline
            Mark Salsbery
            wrote on last edited by
            #5

            In addition to Gideon's reply... Why are you hung up on not using code behind? What's the difference between code generated from the XAML and code you write? It's the same class either way. You could provide individual bool properties to bind the IsChecked properties of each radiobutton to. You could also use a converter to modify the IsChecked properties of the radiobuttons into some other form, like an enum etc.

            Mark Salsbery Microsoft MVP - Visual C++ :java:

            1 Reply Last reply
            0
            • H hhrafn

              well, I'd like to use the radio buttons like this: (in theory at least) <RadioButtons ItemsSource="{Binding Colors}" /> Then picking up the selected item through a selectedItem binding (?) Basically my problem is that I need it to be MVVM (no codebehind) and this radio button list will also be dynamic (changeable).

              A Offline
              A Offline
              ausadmin
              wrote on last edited by
              #6

              I'm not sure if I totally understand your requirement, however you can certainly use MVVM to support a radio button list. Take a look at "Creating an Internationalized Wizard in WPF" [^], in particular the section "Presenting Options via OptionViewModel". In this example the OptionViewModel is used for CheckBox options and RadioButton options. BTW it can be extended for a Combobox - you will see my thread in the discussions for the article, and Karl's solution. I hope this helps. Tim

              H 1 Reply Last reply
              0
              • A ausadmin

                I'm not sure if I totally understand your requirement, however you can certainly use MVVM to support a radio button list. Take a look at "Creating an Internationalized Wizard in WPF" [^], in particular the section "Presenting Options via OptionViewModel". In this example the OptionViewModel is used for CheckBox options and RadioButton options. BTW it can be extended for a Combobox - you will see my thread in the discussions for the article, and Karl's solution. I hope this helps. Tim

                H Offline
                H Offline
                hhrafn
                wrote on last edited by
                #7

                Thank you, this solution looks perfect for me :-D My main requirement in this project is to follow the MVVM pattern, or "total" seperation of View and Code (control). Thanks again.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups