locked
RadioButton group problems RRS feed

  • Question

  • I have a user control that has a series of radio buttons underneath it. I like those controls using a GroupName.

    My problem is when I place multiple versions of the same UserControl on a window/control, the GroupName is shared between the two UserControl's.

    Was wondering what would be the best way to limit the GroupName to exclusively the UserControl and not have it "bleed" outwards.
    Tuesday, September 16, 2008 6:45 AM

Answers

  • It depends on the implementation of your UserControl but usually instanciating a new GroupName in the constructor should be enough because it would create a new reference unless you are thinking ASP like and using the name string to find the RadioButtons from that group.

    Bigsby, Lisboa, Portugal
    • Proposed as answer by Jim Zhou - MSFT Thursday, September 18, 2008 3:02 AM
    • Marked as answer by Marco Zhou Monday, September 22, 2008 10:08 AM
    Tuesday, September 16, 2008 2:23 PM
  • Generate a GroupName when initializing a new UserControl of yours and set it to each RadioButton inside.
    Bigsby, Lisboa, Portugal
    • Marked as answer by Glenn A Watson Monday, September 22, 2008 11:57 AM
    Friday, September 19, 2008 9:17 AM

All replies

  • It depends on the implementation of your UserControl but usually instanciating a new GroupName in the constructor should be enough because it would create a new reference unless you are thinking ASP like and using the name string to find the RadioButtons from that group.

    Bigsby, Lisboa, Portugal
    • Proposed as answer by Jim Zhou - MSFT Thursday, September 18, 2008 3:02 AM
    • Marked as answer by Marco Zhou Monday, September 22, 2008 10:08 AM
    Tuesday, September 16, 2008 2:23 PM
  • At the moment I am doing 

                            <RadioButton GroupName="ColorSelector" Content="H" Margin="3,0,3,0" Width="26" Tag="CurrentColorModel.HHSB" Checked="OnColorRadioButtonClicked" HorizontalContentAlignment="Right" ToolTip="Hue" />

    I am using the string ColorSelector as the GroupName, the theory I had was that i'd have a unique radio button selected for that particular user control only.
    Thursday, September 18, 2008 7:46 AM
  • Generate a GroupName when initializing a new UserControl of yours and set it to each RadioButton inside.
    Bigsby, Lisboa, Portugal
    • Marked as answer by Glenn A Watson Monday, September 22, 2008 11:57 AM
    Friday, September 19, 2008 9:17 AM