WPF: Binding Error, obwohl es funktioniert!?

  • Hallo Leute,

    folgendes Control:

    public class ViewItemBase : Control, INotifyPropertyChanged
    		static ViewItemBase()
    				typeof(ViewItemBase), new FrameworkPropertyMetadata(typeof(ViewItemBase)));
    	#region RotationAngle
    		public double RotationAngle
    			get { return (double)GetValue(RotationAngleProperty); }
    			set { SetValue(RotationAngleProperty, value); }
    		// Using a DependencyProperty as the backing store for RotationAngle.  This enables animation, styling, binding, etc...
    		public static readonly DependencyProperty RotationAngleProperty =
    			DependencyProperty.Register("RotationAngle", typeof(double), typeof(ViewItemBase), new UIPropertyMetadata(0.0, OnRotationChange));
    		private static void OnRotationChange(DependencyObject d, DependencyPropertyChangedEventArgs e)
    			var me = d as ViewItemBase;

    der XAML Style dazu:

    <Style x:Key="{x:Type Model:ViewItemBase}" TargetType="{x:Type Model:ViewItemBase}">
    		<Setter Property="RenderTransformOrigin" Value="0.5,0.5"/>
    		<Setter Property="SnapsToDevicePixels" Value="true"/>
    		<Setter Property="LayoutTransform">
    				<RotateTransform Angle="{Binding RotationAngle, RelativeSource={RelativeSource AncestorType={x:Type Model:ViewItemBase}}}"/>

    Das Binding des RotationTransform Angle funktioniert, aber trotzdem bekomme ich ein Binding error:

    System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='Designer.Core.Controls.Model.ViewItemBase', AncestorLevel='1''. BindingExpression:Path=RotationAngle; DataItem=null; target element is 'RotateTransform' (HashCode=62225447); target property is 'Angle' (type 'Double')

    Was is da falsch ! ?? Obwohl es geht:)

    P.S. Alternativ RelativeSource={RelativeSource TemplateParent} geht nicht,deswegen über die Ancester!!


Log in to reply