test, new Binding(),test和Binding啥关系
解决方案 »
- 经纬度排序
- c#多线程写的socket服务端程序,客户端接收不到应答数据,请大家帮忙看看代码?
- GridView编辑模板列的TextBox
- 将IP地址转换成等效的数字!!很急!
- VS.NET2005正式中文版大概什么时间发布
- 各位前辈,这个程序运行时为什么不能显示连接性质?
- 高薪寻南京C#程序员
- 如何进行用户编号查询的优化?
- 高手请看:用C#能否实现这样的功能?
- Error in adding references for Winform: Ther reference "MSCorLib.dll" was not found !有谁在用VS7的时候遇到这种问题 !
- 去字符串中的内容
- C# 关于线程的问题
Test里的属性先要判断是不是Binding,是Binding就返回Binding的GetValue的值,不是就直接返回值
{
private object _A;
public object A
{
get
{
...
WPF绑定也是对内部的依赖项属性进行设置,而依赖项属性都是用object类型存储的,自然不会出现异常。
比如这样的数据。<Test A="{Binding XXX}" />用XamlReader.Load时,它是直接使用反射去SetValue的,会直接报错。
[ContentProperty("ItemsSource")]
public class ItemsControl : Control
{
public ItemsControl()
{
_Items = new ItemCollection(this);
} public static readonly DependencyProperty ItemTemplateProperty = DependencyProperty.Register("ItemTemplate", typeof(DataTemplate), typeof(ItemsControl));
public DataTemplate ItemTemplate { get { return (DataTemplate)GetValue(ItemTemplateProperty); } set { SetValue(ItemTemplateProperty, value); } }
public static readonly DependencyProperty ItemTemplateSelectorProperty = DependencyProperty.Register("ItemTemplateSelector", typeof(DataTemplateSelector), typeof(ItemsControl));
public DataTemplateSelector ItemTemplateSelector { get { return (DataTemplateSelector)GetValue(ItemTemplateSelectorProperty); } set { SetValue(ItemTemplateSelectorProperty, value); } } private ItemCollection _Items;
[Category("Common Properties")]
public ItemCollection Items { get { return _Items; } } internal Panel ItemsPanelElement;
public static readonly DependencyProperty ItemsPanelProperty = DependencyProperty.Register("ItemsPanel", typeof(ItemsPanelTemplate), typeof(ItemsControl));
public ItemsPanelTemplate ItemsPanel { get { return (ItemsPanelTemplate)GetValue(ItemsPanelProperty); } set { SetValue(ItemsPanelProperty, value); } } public static readonly DependencyProperty ItemsSourceProperty = DependencyProperty.Register("ItemsSource", typeof(IEnumerable), typeof(ItemsControl));
[Category("Common Properties")]
public IEnumerable ItemsSource { get { return (IEnumerable)GetValue(ItemsSourceProperty); } set { SetValue(ItemsSourceProperty, value); } }
}
WPF中的Binding是通过SetBinding与依赖项属性关联的,而不是作为值赋值给某个属性,你却将自己定义的一个名为Binding的类,作为值赋值给某个属性,自然要出错,运行原理是不同的。
我现在写了个TypeDescriptionProvider,但是没有被调用……
取到类型名称后,就可以判断转换你想要的动作了?