文本框RadioButton代码 [英] Textbox RadioButton Code

查看:79
本文介绍了文本框RadioButton代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

绑定文本框和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 RadioButtons, you can set the GroupName property of the RadioButtons to the same value. For enabling a TextBox according to the RadioButton's state, you can use the ElementName property of the Binding. For instance, see the following StackPanel:

<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 disabled TextBox, you can set the TextBox as a part of the Content of the RadioButton, like in the following StackPanel:

<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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆