文本框RadioButton代码 [英] Textbox RadioButton Code
问题描述
绑定文本框和RadioButton
如果您只想在文本框具有焦点时检查RadioButton,这也适用:
< radiobutton ischecked ={Binding IsFocused,ElementName = txtBox,Mode = OneWay}>
< textbox x:name =txtBoxxmlns:x =#unknown/>
< / radiobutton>
为了将同一组设置为某些
RadioButton
s,您可以将RadioButton
的GroupName
属性设置为相同的值。要根据RadioButton
的状态启用TextBox
,您可以使用ElementName
Binding
的属性。例如,请参阅以下StackPanel
:< StackPanel >
< StackPanel 方向 = 水平 保证金 = 2 >
< RadioButton 名称 = op1 内容 = 选项1: GroupName = / >
< TextBox 宽度 = 200 IsEnabled = {Binding IsChecked,ElementName = op1} / >
< / StackPanel >
< StackPanel < span class =code-attribute> 方向 = 水平 保证金 = 2 >
< RadioButton 名称 = op2 内容 = 选项2: GroupName = / >
< TextBox 宽度 = 200 IsEnabled = {Binding IsChecked,ElementName = op2} / >
< < span class =code-leadattribute> / StackPanel >
< StackPanel 方向 = 水平 保证金 = 2 >
< RadioButton 名称 = < span class =code-keyword> op3 内容 = 选项3: GroupName = / >
< TextBox 宽度 = 200 IsEnabled = {绑定IsChecked,ElementName = op3} / >
< / StackPanel > ;
< StackPanel 方向 = 水平 Mar杜松子酒 = 2 >
< RadioButton 名称 = op4 < span class =code-attribute> 内容 = 选项4: GroupName = / >
< TextBox 宽度 = 200 IsEnabled = {Binding IsChecked,ElementName = op4} / >
< / StackPanel >
< StackPanel 方向 = 水平 保证金 = 2 >
< RadioButton 名称 = op5 内容 = 选项5: GroupName = A / >
< TextBox 宽度 = 200 IsEnabled = {Binding IsChecked,ElementName = op5} / >
< / StackPanel < span class =code-keyword>>
< / StackPanel >
已编辑:
如果要在单击禁用的
TextBox
时检查RadioButton
,可以设置TextBox
作为RadioButton
的内容
的一部分,如以下StackPanel
:< StackPanel >
< RadioButton 名称 = op1 GroupName = 保证金 = 2 >
< RadioButton.Content > ;
< StackPanel 方向 = 水平 >
< TextBlock Text = 选项1: / >
< TextBox 宽度 = 200 IsEnabled = {Binding IsChecked,ElementName = op1} / >
< / StackPanel >
< / RadioButton.Content >
< / RadioButton >
< RadioButton 名称 = op2 GroupName = 保证金 = 2 >
< RadioButton.Content >
< StackPanel 方向 = 水平 >
< TextBlock 文字 = 选项2: / >
< TextBox 宽度 = 200 IsEnabled = {Binding IsChecked,ElementName = op2} / >
< / StackPanel >
< / RadioButton.Content >
< / RadioButton >
< < span class =code-leadattribute> RadioButton 名称 = op3 GroupName = A 保证金 = 2 >
< RadioButton.Content >
< StackPanel 方向 = 水平 >
< TextBlock 文字 = 选项3: / >
< TextBox 宽度 = 200 IsEnabled = {Binding IsChecked,ElementName = op3} / >
< / StackPanel >
< / RadioButton.Content >
< / RadioButton >
< RadioButton < span class =code-attribute> 名称 = op4 GroupName = 保证金 = 2 >
< RadioButton.Content >
< Stack面板 方向 = 水平 >
< TextBlock 文本 = 选项4: / >
< TextBox 宽度 = 200 IsEnabled = {Bin ding IsChecked,ElementName = op4} / >
< / StackPanel >
< / RadioButton.Content >
< / RadioButton < span class =code-keyword>>
< RadioButton 名称 = op5 GroupName = A 保证金 = 2 >
< RadioButton.Content >
< StackPanel 方向 = 水平 >
< TextBlock 文字 = 选项5: < span class =code-keyword> / >
< TextBox 宽度 = 200 IsEnabled = {Binding IsChecked,ElementName = op5} / < span class =code-keyword>>
< / StackPanel >
< / RadioButton。内容 >
< / RadioButton >
< / StackPanel > 跨度>
Binding Textbox and RadioButton
If you just want the RadioButton checked when the textbox has focus, this works too:
<radiobutton ischecked="{Binding IsFocused, ElementName=txtBox, Mode=OneWay}"> <textbox x:name="txtBox" xmlns:x="#unknown" /> </radiobutton>
In order to set the same group to some
RadioButton
s, you can set theGroupName
property of theRadioButton
s to the same value. For enabling aTextBox
according to theRadioButton
's state, you can use theElementName
property of theBinding
. For instance, see the followingStackPanel
:<StackPanel> <StackPanel Orientation="Horizontal" Margin="2"> <RadioButton Name="op1" Content="Option 1: " GroupName="A" /> <TextBox Width="200" IsEnabled="{Binding IsChecked, ElementName=op1}" /> </StackPanel> <StackPanel Orientation="Horizontal" Margin="2"> <RadioButton Name="op2" Content="Option 2: " GroupName="A" /> <TextBox Width="200" IsEnabled="{Binding IsChecked, ElementName=op2}" /> </StackPanel> <StackPanel Orientation="Horizontal" Margin="2"> <RadioButton Name="op3" Content="Option 3: " GroupName="A" /> <TextBox Width="200" IsEnabled="{Binding IsChecked, ElementName=op3}" /> </StackPanel> <StackPanel Orientation="Horizontal" Margin="2"> <RadioButton Name="op4" Content="Option 4: " GroupName="A" /> <TextBox Width="200" IsEnabled="{Binding IsChecked, ElementName=op4}" /> </StackPanel> <StackPanel Orientation="Horizontal" Margin="2"> <RadioButton Name="op5" Content="Option 5: " GroupName="A" /> <TextBox Width="200" IsEnabled="{Binding IsChecked, ElementName=op5}" /> </StackPanel> </StackPanel>
Edited:
If you want the
RadioButton
to be checked when you click on the disabledTextBox
, you can set theTextBox
as a part of theContent
of theRadioButton
, like in the followingStackPanel
:<StackPanel> <RadioButton Name="op1" GroupName="A" Margin="2"> <RadioButton.Content> <StackPanel Orientation="Horizontal"> <TextBlock Text="Option 1: " /> <TextBox Width="200" IsEnabled="{Binding IsChecked, ElementName=op1}" /> </StackPanel> </RadioButton.Content> </RadioButton> <RadioButton Name="op2" GroupName="A" Margin="2"> <RadioButton.Content> <StackPanel Orientation="Horizontal"> <TextBlock Text="Option 2: " /> <TextBox Width="200" IsEnabled="{Binding IsChecked, ElementName=op2}" /> </StackPanel> </RadioButton.Content> </RadioButton> <RadioButton Name="op3" GroupName="A" Margin="2"> <RadioButton.Content> <StackPanel Orientation="Horizontal"> <TextBlock Text="Option 3: " /> <TextBox Width="200" IsEnabled="{Binding IsChecked, ElementName=op3}" /> </StackPanel> </RadioButton.Content> </RadioButton> <RadioButton Name="op4" GroupName="A" Margin="2"> <RadioButton.Content> <StackPanel Orientation="Horizontal"> <TextBlock Text="Option 4: " /> <TextBox Width="200" IsEnabled="{Binding IsChecked, ElementName=op4}" /> </StackPanel> </RadioButton.Content> </RadioButton> <RadioButton Name="op5" GroupName="A" Margin="2"> <RadioButton.Content> <StackPanel Orientation="Horizontal"> <TextBlock Text="Option 5: " /> <TextBox Width="200" IsEnabled="{Binding IsChecked, ElementName=op5}" /> </StackPanel> </RadioButton.Content> </RadioButton> </StackPanel>
这篇关于文本框RadioButton代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!