locked
How to auto-select a radio button RRS feed

  • Question

  • Hello everyone,

    I built a GUI using xaml for a PowerShell script and have 2 radio buttons on it. I would like to set it up so when I highlight a textbox, radio2 is automatically selected if radio1 is currently selected.  Conversely, when a button is clicked, radio1 should be selected if radio 2 is selected.

    Here are the excerpts of my code that should be relevant...

    From the XAML portion:

            <RadioButton x:Name="Radio1" Content="Choose list from external file:" IsChecked="True" HorizontalAlignment="Left" Margin="56,85,0,0" VerticalAlignment="Top"/>
            <RadioButton x:Name="Radio2" Content="Use devices below:&#xD;&#xA;" HorizontalAlignment="Left" Margin="56,103,0,0" VerticalAlignment="Top" />
            <Button x:Name="ButtonBrowse" Content="Browse" HorizontalAlignment="Left" Margin="120,83,0,0" VerticalAlignment="Top" Width="75"  Grid.Column="1"/>
            <TextBox x:Name="InputBox" HorizontalAlignment="Left" Height="99" Margin="56,119,0,0" VerticalAlignment="Top" Width="166" VerticalScrollBarVisibility="Auto" ScrollViewer.CanContentScroll="True" AcceptsReturn="True"/>
    
    
    

    From the PS portion:

    $Radio1 = $Form.FindName("Radio1")
    $Radio2 = $Form.FindName("Radio2")
    $InputBox = $Form.FindName("InputBox")
    $ButtonBrowse = $Form.FindName("ButtonBrowse")
    
    $ButtonBrowse.Add_Click({
        misc code...
        if ($radio2.isChecked){
            $radio1.ischecked}
    })

    I couldn't get the browse button to function, so I didn't even attempt the part where selecting a textbox auto-selects radio2.

    Thank you for any help!

    Wednesday, December 20, 2017 8:29 PM

Answers

  • To select a radio button set it to "IsChecked"

    $radio.IsChecked = $true


    \_(ツ)_/

    • Marked as answer by Codyyoung37 Wednesday, December 20, 2017 8:43 PM
    Wednesday, December 20, 2017 8:38 PM

All replies

  • To select a radio button set it to "IsChecked"

    $radio.IsChecked = $true


    \_(ツ)_/

    • Marked as answer by Codyyoung37 Wednesday, December 20, 2017 8:43 PM
    Wednesday, December 20, 2017 8:38 PM
  • Ha, for some reason that took me an abnormal amount of effort to figure out.  Thank you!
    Wednesday, December 20, 2017 8:43 PM