2013-05-30 55 views
2

對不起,模糊(ish)標題,我正在一個WPF項目,它變得相當討厭。我知道,VS設計師有時候有點費勁,但希望能夠解決這個問題。VS2010 XAML設計器綁定錯誤,但一般運行良好

我已經得到了我把綁定過,但是設計師給我藍色的波浪線和一個錯誤的依賴屬性:

Error 13 A 'Binding' cannot be used within a 'TextBlock' collection. A 'Binding' can only be set on a DependencyProperty of a DependencyObject.

然而,當我運行應用程序,這一切都工作正常,沒有綁定錯誤,這一切都按預期工作。 VS自首次發生以來已經多次重啓,並且仍然會發生。

我看不出它所指的DependancyProperty有什麼問題,對我來說都是相當標準的,但也許你們中的一個可以擺脫一些光線(希望)。我不記得我從哪裏得到DP的代碼,我知道它是在線的,但我已經從那裏調整(我想)。

運行VS2010,項目的目標是.net4.0(不是客戶端配置文件)。

謝謝!

XAML

<TextBlock Grid.Column="1" Grid.Row="0" AllowDrop="True" behaviours:DropBehavior.PreviewDropCommand="{Binding Path=DropFile}" Style="{StaticResource styFile}"> 

DP

public static class DropBehavior { 

    private static readonly DependencyProperty PreviewDropCommandProperty = DependencyProperty.RegisterAttached(
     "PreviewDropCommand", 
     typeof(ICommand), 
     typeof(DropBehavior), 
     new PropertyMetadata(null, PreviewDropCommandPropertyChangedCallBack) 
    ); 

    public static void SetPreviewDropCommand(this UIElement inUIElement, ICommand inCommand) { 
     inUIElement.SetValue(PreviewDropCommandProperty, inCommand); 
    } 

    private static ICommand GetPreviewDropCommand(UIElement inUIElement) { 
     return (ICommand)inUIElement.GetValue(PreviewDropCommandProperty); 
    } 

    private static void PreviewDropCommandPropertyChangedCallBack(
     DependencyObject inDependencyObject, DependencyPropertyChangedEventArgs inEventArgs) { 
     UIElement uiElement = inDependencyObject as UIElement; 
     if (null == uiElement) 
      return; 

     uiElement.Drop += (sender, args) => { 
      GetPreviewDropCommand(uiElement).Execute(args.Data); 
      args.Handled = true; 
     }; 
    } 
} 

回答

2

多搭UI抱怨它,又採取了另一個看問題後,原來這裏是這條線:

private static readonly DependencyProperty PreviewDropCommandProperty = DependencyProperty.RegisterAttached(
    "PreviewDropCommand", 
    typeof(ICommand), 
    typeof(DropBehavior), 
    new PropertyMetadata(null, PreviewDropCommandPropertyChangedCallBack) 
); 

它應該是public,而不是private聲明。好奇的是,應用程序運行良好,只是不是設計師(或者如果我知道VS的內部工作原理可能不那麼好奇)

相關問題