A'绑定'不能在类型的'头'属性'MiniListView“进行设置。 A'绑定'只能在DependencyObject的一个DependencyProperty的设置 [英] A 'Binding' cannot be set on the 'Headers' property of type 'MiniListView'. A 'Binding' can only be set on a DependencyProperty of a DependencyObject

查看:1121
本文介绍了A'绑定'不能在类型的'头'属性'MiniListView“进行设置。 A'绑定'只能在DependencyObject的一个DependencyProperty的设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面我code,

    <StackPanel HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,43,43,0">
        <mine:MiniListView x:Name="Mini" Width="300" Headers="{Binding MyHeaders}"></mine:MiniListView>
        <Button HorizontalAlignment="Right" Margin="0" FontSize="10" Content="Add Row" Width="70" Height="20" />
    </StackPanel>

幕后code:

    public Dictionary<string, string> MyHeaders
    {
        get
        {
            Dictionary<string, string> dic = new Dictionary<string, string>();
            dic.Add("NAME", "BRANCH"); dic.Add("BANKNAME", "Percentage");
            return dic;
        }
    }

自定义类矿井:ministView

public class MiniListView : ListView
{
   public static DependencyProperty HeadersProperty;
   public Dictionary<string, string> Headers
   {
      get { return (Dictionary<string, string>)base.GetValue(HeadersProperty); }
      set { base.SetValue(HeadersProperty, value); }
   }
   public MiniListView()
    {
        HeadersProperty = DependencyProperty.Register("Headers", typeof(Dictionary<string, string>), typeof(MyListView));
        this.View = MyGrid();
    }
}

在这里,我想bindminlistivew头的带MyHeaders财产,收到此错误

Here i'm trying to bindminlistivew HEADER'S PROPERTY WITH MyHeaders, getting this error

A'绑定'不能在类型的'头'属性'MiniListView设置。 A'绑定'只能在一个设定的DependencyProperty   为DependencyObject。

A 'Binding' cannot be set on the 'Headers' property of type 'MiniListView'. A 'Binding' can only be set on a DependencyProperty of a DependencyObject.

请告诉我,什么是错的在我的code。

please tell me what's wrong in my code.

感谢您,

推荐答案

所有者类型不正确。它应该是 MiniListView ,而不是 MyListView

Owner type in dependency property registration is incorrect. It should be MiniListView and not MyListView

HeadersProperty = DependencyProperty.Register("Headers",
                   typeof(Dictionary<string, string>), typeof(MiniListView));

这篇关于A'绑定'不能在类型的'头'属性'MiniListView“进行设置。 A'绑定'只能在DependencyObject的一个DependencyProperty的设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆