开发者

WPF Radiobutton equivalent

What开发者_Python百科 is the WPF equivalent for WinForms radio button CheckedChanged?

I have your basic 2 radio button set up, where when one is selected a textbox is enabled and when the other is selected it is disabled.

For the time being I was using RadioButton_Checked, except, I set IsChecked true for one button in the xaml. When I reference the textbox in that Checked method it throws NullReferenceException...

edit:

XAML:

<RadioButton Name="rb1" IsChecked="True" GroupName="1" Checked="rb1_Checked"></RadioButton>

<RadioButton Name="rb2" GroupName="1" Checked="rb2_Checked"></RadioButton>

C#:

    private void rb2_Checked(object sender, RoutedEventArgs e)
    {
        txt.IsEnabled = false;
    }

    private void rb1_Checked(object sender, RoutedEventArgs e)
    {
        txt.IsEnabled = true; //null reference here on load
    }


Can't you bind the enabled property of the textbox to the checked property of the appropriate radio button in your xaml?

<Textbox IsEnabled="{Binding ElementName=rb2, Path=IsChecked}" />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜