您还没有描述用户如何更改目标依赖项属性。你能把
DependencyProperty
他们自己而不是
string
S?这样你就不用做任何转换了。伪代码:
//just an array of all allowable properties
public DependencyProperty[] AllowedProperties { get; }
//the property the user has chosen
public DependencyProperty ChosenProperty { get; set; }
//called whenever ChosenProperty changes
private void OnChosenPropertyChanged()
{
//redo binding here, using ChosenProperty as the target
}
评论后编辑
:如果知道所有者的类型,则可以使用DependencyPropertyDescriptor.FromName从其名称中获取DependencyProperty:
var descriptor = DepedencyPropertyDescriptor.FromName(nameFromExcel, typeof(YourUserControl), typeof(YourUserControl));
var dependencyProperty = descriptor.DependencyProperty;