【问题标题】:WPF Radio ButtonsWPF 单选按钮
【发布时间】:2021-08-30 12:19:44
【问题描述】:

我正在 Visual Studio 上创建单选按钮,但我遇到了绑定问题

这是我的按钮:

<RadioButton VericalAlignment="Center" GroupName="group1" Content="name"></RadioButton>

我希望如果按钮被选中,那么 {"someString " + Content Value} 的值将被绑定 到 SomeClass.variable

这样的事情可能吗? 谢谢!

【问题讨论】:

  • 处理Checked 事件?

标签: wpf xaml radio-button


【解决方案1】:

这样的事情应该可以工作:

XAML:

<Window x:Class="StackOverflowRadioButton.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:StackOverflowRadioButton"
    mc:Ignorable="d"
    Title="MainWindow" Height="450" Width="800">
<Grid Margin="81,36,-81,-36">
    <RadioButton Content="RadioButton" HorizontalAlignment="Left" Margin="111,135,0,0" VerticalAlignment="Top"
                 Name="myRadioButton" Checked="myRadioButton_Checked"/>
</Grid>

CS 文件:

using System.Windows;

namespace StackOverflowRadioButton
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public string someVariable;
        public MainWindow()
        {
            InitializeComponent();
        }

        private void myRadioButton_Checked(object sender, RoutedEventArgs e)
        {
            someVariable = "someString " + myRadioButton.IsChecked;
        }
    }
}

【讨论】:

    猜你喜欢
    • 2011-09-16
    • 1970-01-01
    • 1970-01-01
    • 2011-01-26
    • 2013-10-28
    • 1970-01-01
    • 2012-12-10
    • 2011-06-01
    • 1970-01-01
    相关资源
    最近更新 更多