あいまいな(っぽい)タイトルで申し訳ありません。私はWPFプロジェクトに取り組んでおり、かなり面倒です。VS デザイナーが少し気難しいこともありますが、修正できることを願っています。
私もバインディングを配置している依存関係プロパティを持っていますが、デザイナーは私に青い波線とエラーを与えています:
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 に問題は見られません。私にはすべてがかなり標準的に見えますが、おそらく皆さんの 1 人が光を当てることができます (うまくいけば)。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;
};
}
}