wpf - WPF 单选按钮
问题描述
我在 Visual Studio 上创建单选按钮,但我遇到了绑定问题
这是我的按钮:
<RadioButton VericalAlignment="Center" GroupName="group1" Content="name"></RadioButton>
我希望如果选择了按钮,则 {"someString" + Content Value} 的值将绑定到 SomeClass.variable
这样的事情可能吗?谢谢!
解决方案
像这样的东西应该工作:
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;
}
}
}
推荐阅读
- typescript - 如何在 Vue2 中对去抖动的计算设置器进行类型转换?
- javascript - 将图像裁剪输出到 base64 的反应不起作用
- javascript - 如何计算 ID 相同的平均值,然后删除该 ID 的重复项,但保留在 javascript 中具有平均值的 ID
- python - 没有任何特殊符号和空格的sqlalchemy自定义字符串
- ios - iOS 应用内购买自动续订订阅在管理订阅页面上显示不正确
- node.js - 如何在编译为 .exe 时包含 Node.js 本机模块
- vue.js - 嵌套路由问题vue 3
- swift - 当代码另有说明时,是否基于碰撞移除 Sprite 对象?
- android - 如何在 Android 中设置 AWS SNS 推送通知
- gson - Gson如何将JSON转化为带有TypeToken的bean对象?