A'绑定'不能在类型的'头'属性'MiniListView“进行设置。 A'绑定'只能在DependencyObject的一个Dependenc

由网友(心若向阳,何来畏惧)分享简介:下面我code,下面我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));
阅读全文

相关推荐

最新文章