我有一个简单的类,ClassA(下)。是否有可能在我的 XAML 转发器中将反射的属性名称绑定到文本框并能够将复选框 IsChecked 绑定到 bool 属性?所以我的 XAML 可能类似于(这只是伪 xaml,不确定它在语法上是否正确,并假设 ItemsControl 数据上下文是 ClassA):
<ItemsControl>
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBox Text="{Binding ??? reflected property name as text, e.g., ClassABool1 ??? }"
<CheckBox IsChecked="{Binding ??? somehow bind to the actual property ClassABool1 ???, Mode=TwoWay}"
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
public sealed class ClassA : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private static ClassA _instance;
private ClassA() {}
public static ClassA Instance
{
get
{
if (_instance == null)
{
_instance = new ClassA();
}
return _instance;
}
}
private bool _classABool1;
public bool ClassABool1 { get; set; }
private bool _classABool2;
public bool ClassABool2 { get; set; }
}