wpf Canvasクラスから派生した 'MyCanvas'というカスタムクラスがあります。 MyCanvasには、キャンバスのスケール変換を指定するDependency Property 'Scale'があります。 Scaleの値が変わると、変換を古い値から新しい値にアニメートしたいと思っています。そのため私はLayoutTransform.BeginAnimation(...)
メソッドを使用しています。ScaleXとScaleYのLayoutTransformアニメーションはバインディングを中断しています
コード:
//This represents the time it will take to zoom
Duration zoomDuration = new Duration(TimeSpan.Parse("0:0:0.3"));
//Set up animation for zooming
DoubleAnimationUsingKeyFrames scaleAnimation = new DoubleAnimationUsingKeyFrames();
scaleAnimation.Duration = zoomDuration;
scaleAnimation.KeyFrames = GetAnimationSplines(newScale);
scaleAnimation.Completed += new EventHandler(
(sender, e) => Scale = newScale);
// Start the scale (zoom) animations
LayoutTransform.BeginAnimation(ScaleTransform.ScaleXProperty, scaleAnimation);
LayoutTransform.BeginAnimation(ScaleTransform.ScaleYProperty, scaleAnimation);
のXmaI:
<Grid>
<ItemsControl x:Name="Items">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<local:MyCanvas Scale="{Binding Scale, Mode=TwoWay}">
<local:MyCanvas.LayoutTransform UseLayoutRounding="True">
<ScaleTransform ScaleX="{Binding Scale, Mode=TwoWay}"
ScaleY="{Binding Scale, Mode=TwoWay}"/>
</local:MyCanvas.LayoutTransform>
</local:MyCanvas>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</Grid>
しかしScale
(のviewmodelでプロパティ)とScaleX
とScaleY
の結合、このコードを実行した後
Scale
の値を変更すること、すなわち破壊されませんキャンバスの縮尺を変更しない。 (スヌープを使用して)
エラーメッセージ:
System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=Scale; DataItem=null; target element is 'ScaleTransform' (HashCode=796423); target property is 'ScaleX' (type 'Double')
System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=Scale; DataItem=null; target element is 'ScaleTransform' (HashCode=796423); target property is 'ScaleY' (type 'Double')
いずれかが、このためのソリューションを持っている場合は私に知らせてください。ありがとう
ScaleTransformをLayoutTransformプロパティにどのように割り当てましたか?そのコードも表示してください。それともあなたは? – Clemens