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
  1. Home
  2. General Programming
  3. WPF
  4. WPF Bind Radio Buttons To Tab Control

WPF Bind Radio Buttons To Tab Control

Scheduled Pinned Locked Moved WPF
questioncsharpwpfhelp
7 Posts 7 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.
  • K Offline
    K Offline
    Kevin Marois
    wrote on last edited by
    #1

    How do I bind a set of radio buttons to a tab control, so when button 0 is clicked, tab 0 is active, 1 is clicked, tab 1 is active, etc? Thanks

    If it's not broken, fix it until it is

    Y M L S M 6 Replies Last reply
    0
    • K Kevin Marois

      How do I bind a set of radio buttons to a tab control, so when button 0 is clicked, tab 0 is active, 1 is clicked, tab 1 is active, etc? Thanks

      If it's not broken, fix it until it is

      Y Offline
      Y Offline
      YBirkhoff
      wrote on last edited by
      #2

      In beginners tongue, You might need to create a new variable that will act as the connector, so that if the value of the radio button is changed, the value of the variable changes and so the corresponding tab is activated.

      1 Reply Last reply
      0
      • K Kevin Marois

        How do I bind a set of radio buttons to a tab control, so when button 0 is clicked, tab 0 is active, 1 is clicked, tab 1 is active, etc? Thanks

        If it's not broken, fix it until it is

        M Offline
        M Offline
        Mycroft Holmes
        wrote on last edited by
        #3

        Personally I'd wire it up via the VM, I presume you want this done via XAML!

        Never underestimate the power of human stupidity RAH

        1 Reply Last reply
        0
        • K Kevin Marois

          How do I bind a set of radio buttons to a tab control, so when button 0 is clicked, tab 0 is active, 1 is clicked, tab 1 is active, etc? Thanks

          If it's not broken, fix it until it is

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Have the Radio button IsSelected modify the SelectedItem thus triggering the Tab selection to change.

          private void PropertyChangeHandler(object sender, PropertyChangedEventArgs e)
          {
          if(e.PropertyName == "IsSelected")
          {
          SelectedItem = sender;
          }
          }

          public object SelectedItem
          {
          public get {return _selectedItem;}
          public set
          {
          if(_selecteItem == value)return;
          _selecteItem = value;
          RaisePropertyChange("SelectedItem");
          }

          }

          And of course have your TabControl set up to use the SelecteItem.

          Computers have been intelligent for a long time now. It just so happens that the program writers are about as effective as a room full of monkeys trying to crank out a copy of Hamlet.

          1 Reply Last reply
          0
          • K Kevin Marois

            How do I bind a set of radio buttons to a tab control, so when button 0 is clicked, tab 0 is active, 1 is clicked, tab 1 is active, etc? Thanks

            If it's not broken, fix it until it is

            S Offline
            S Offline
            SledgeHammer01
            wrote on last edited by
            #5

            They don't really have the concept of "the selected radio button index" in WPF. Kind of lame. You either have to do the mapping by hand (winforms style) or pass in the hard-coded index via a command parameter. If you are trying to write "professional & re-usable" code, I'd suggest going the route that I did. Create a "RadioButtonGroup" control thats derived from ItemsControl. Your ItemsSource would be an array of strings (or whatever) and your ItemTemplate would simply be a RadioButton that sets up all the bindings for you. Then you would have bindable SelectedRadioButton and/or SelectedRadioButtonIndex properties, so on and so forth. Sounds like a bit of work (its not really), but I'm assuming you are building a generic re-usable library that you'll toss this in and use on future projects :).

            1 Reply Last reply
            0
            • K Kevin Marois

              How do I bind a set of radio buttons to a tab control, so when button 0 is clicked, tab 0 is active, 1 is clicked, tab 1 is active, etc? Thanks

              If it's not broken, fix it until it is

              M Offline
              M Offline
              Martijn Kok
              wrote on last edited by
              #6

              In XAML you could do this by binding the tabItems IsSelected to the IsChecked from the radiobutton. See the example below (for the sake of this example I removed some attributes like Height and Margin)

              <Grid>
                  <TabControl Name="tabControl1" >
                      <TabItem Header="tabItem1" Name="tabItem1" IsSelected="{Binding ElementName=radioButton1, Path=IsChecked, Mode=TwoWay}">
                          <Grid />
                      </TabItem>
                      <TabItem Header="tabItem2" Name="tabItem2" IsSelected="{Binding ElementName=radioButton2, Path=IsChecked, Mode=TwoWay}">
                          <Grid />
                      </TabItem>
                  </TabControl>
                  <RadioButton Content="1" Name="radioButton1" IsChecked="True"/>
                  <RadioButton Content="2"  Name="radioButton2" />
              </Grid>
              
              1 Reply Last reply
              0
              • K Kevin Marois

                How do I bind a set of radio buttons to a tab control, so when button 0 is clicked, tab 0 is active, 1 is clicked, tab 1 is active, etc? Thanks

                If it's not broken, fix it until it is

                C Offline
                C Offline
                Clifford Nelson
                wrote on last edited by
                #7

                You can always create a IValueConverter. Bind to the TabControl

                SelectedIndex

                . On each RadioButton, use the ConverterParameter to pass the value that should set the RadioButton to IsChecked. The IValueConverter class is pretty straight forward.

                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