我正在学习C#并构建一个读取和写入整数到XML配置文件的UI.UI使用各种自定义用户控件.我有一个3 radiobutton用户控件绑定到单个int变量(控件返回0,1,2).控件使用事件来触发更新.它查看3个isChecked属性以确定新的int值.但我不知道如何从后面的代码更新原始绑定值.它曾被删除,因为有两个绑定..一个在主窗口中,一个在用户控件中.作为初学者,我在这一点上迷失了方向.BTW将int值读入3个radiobutton正在使用转换器.
这是用户控件xaml.cs ...
namespace btsRV7config.controls
{
public partial class ui3X : UserControl
{
public ui3X()
{
InitializeComponent();
}
void _event(object sender, RoutedEventArgs e)
{
int newValue = 0;
if (rdbttn1.IsChecked == true) { newValue = 0; }
else if (rdbttn2.IsChecked == true) { newValue = 1; }
else if (rdbttn3.IsChecked == true) { newValue = 2; }
txtb.Text = newValue.ToString(); //tempRemove
// !!! assign newValue to Binding Source !!!
//---------------------------------------------
uiBinding1 = newValue;
BindingOperations.GetBindingExpression(rdbttn1, RadioButton.IsCheckedProperty).UpdateSource();
//---------------------------------------------
}
public static …
Run Code Online (Sandbox Code Playgroud)