private void _fnTest(FrameworkElement FE)
{
 Binding a;
 if (FE is ComboBox)
   a=(FE as ComboBox).GetBindingExpression(ComboBox.SelectedValueProperty).ParentBinding;
 //如果是一个未知类型(由于是未知类型无法强制转换), 先判断它是否有SelectValue属性,如果有则获取它的Binding
 else if (FE.GetBindingExpression(这里要怎么写.SelectedValueProperty) != null)
    a= FE.GetBindingExpression(这里要怎么写.SelectedValueProperty).ParentBinding;//判断是否具有IsReadOnly属性,如果有则将它设置为true    
if (AFE.GetType().GetProperty("IsReadOnly")!=null)
   这里怎么给它赋值
}

解决方案 »

  1.   

    AFE.GetType().GetProperty("IsReadOnly").SetValue
      

  2.   

    ctrl.GetType().GetProperty("Text").GetValue(ctrl, null).ToString();
    ctrl.GetType().GetProperty("Text").SetValue(ctrl, null)
      

  3.   

    Dependency Property是一个Static Readonly的Field,而不是Property private void _fnTest(FrameworkElement FE)
            {
                Binding a;            var fi = FE.GetType().GetField("SelectedValueProperty", BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy);
                if (fi != null && fi.FieldType == typeof(DependencyProperty))
                {
                    var dp = fi.GetValue(null) as DependencyProperty;
                    var be = FE.GetBindingExpression(dp);
                    if(be != null)
                        a = be.ParentBinding;
                }            var pi = FE.GetType().GetProperty("IsReadOnly", BindingFlags.Instance | BindingFlags.Public);
                if (pi != null && pi.CanWrite)
                {
                    pi.SetValue(FE, true, null);
                }
            }
      

  4.   

    http://caliburn.codeplex.com/Thread/View.aspx?ThreadId=228952