'True'不是属性'IsDragSource'的有效值

时间:2014-08-03 18:17:17

标签: c# wpf xaml dependency-properties

我对WPF依赖属性有一个奇怪的问题:

/// <summary>
/// attached property that defines if the source is a drag source
/// </summary>
public static readonly DependencyProperty IsDragSourceProperty =
    DependencyProperty.RegisterAttached("IsDragSource", 
        typeof(bool?), 
        typeof(DragDropBehaviour),
        new PropertyMetadata(null, 
            new IsDragSourceBehaviour().PropertyChangedHandler));

当我尝试在我的XAML窗口中使用它时,它给了我卷曲的线条。

<ListBox IsSynchronizedWithCurrentItem="True"
         AllowDrop="False"
         ItemsSource="{Binding Objects, Mode=TwoWay}" 
         i:DragDropBehaviour.DragDropHandler="{Binding}"
         i:DragDropBehaviour.IsDragSource="True" Grid.Column="0"/>

...声明&#39; True&#39;不是财产的有效价值&#39; IsDragSource&#39;。如果我说的话,True应该是类型(bool?)的依赖属性的有效属性值。

我的错误是什么?

该应用程序工作正常,但我不喜欢我的XAML中的红色,卷曲的线条。

编辑...

我找到了它,原因是在两个Get / Set方法中找到的:

/// <summary>
    /// attached property that defines if the source is a drag source
    /// </summary>
    public static readonly DependencyProperty IsDragSourceProperty =
       DependencyProperty.RegisterAttached("IsDragSource",
       typeof(bool?),
       typeof(DragDropBehaviour),
       new PropertyMetadata(null, new IsDragSourceBehaviour().PropertyChangedHandler));

    public static void SetIsDragSource(DependencyObject o, bool? propertyValue)
    {
        o.SetValue(IsDragSourceProperty, propertyValue);
    }
    public static bool? GetIsDragSource(DependencyObject o)
    {
        return (bool?)o.GetValue(IsDragSourceProperty);
    }

他们使用的是对象而不是bool?

0 个答案:

没有答案