none
ItemsPanelTemplate里的Canvas的RenderTransform不可操作 RRS feed

  • 问题

  • 问下 我有个 ItemsControl ItemsControl的 ItemsPanel的 Template 是 Canvas 我想设置多点触摸 所以 Canvas的Rendertransform 设置为 MatrixTransform 但后台提示属性为只读,  如果不是在模版里的Canvas就可以 ... 求教  上代码...

     <ItemsControl     >
            <ItemsControl.RenderTransform>
                <MatrixTransform></MatrixTransform>
            </ItemsControl.RenderTransform>
    
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate >
                    <!-- 图层的面板 -->
                    <Canvas Name="canvas"      IsManipulationEnabled="true"
                            ManipulationStarting="image_ManipulationStarting"  
                    ManipulationDelta="image_ManipulationDelta"
                    ManipulationCompleted="image_ManipulationCompleted" >
                        <Canvas.RenderTransform>
                            <MatrixTransform />
                        </Canvas.RenderTransform>
    </Canvas>
     </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
        </ItemsControl>

    后台...

    private void image_ManipulationStarting(object sender, ManipulationStartingEventArgs e)
            {
                e.ManipulationContainer = this;
                e.Mode = ManipulationModes.All;
                //e.IsSingleTouchEnabled = false;
            }
    
            private void image_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
            {
                FrameworkElement element = (FrameworkElement)e.Source;
                //element.Opacity = 0.5;
    
                Matrix matrix = ((MatrixTransform)element.RenderTransform).Matrix;
    
                var deltaManipulation = e.DeltaManipulation;
    
                Point center = new Point(element.ActualWidth / 2, element.ActualHeight / 2);
                center = matrix.Transform(center);
    
                //缩放
                matrix.ScaleAt(deltaManipulation.Scale.X, deltaManipulation.Scale.Y, center.X, center.Y);
                //旋转
                //matrix.RotateAt(e.DeltaManipulation.Rotation, center.X, center.Y);
                //位移
                matrix.Translate(e.DeltaManipulation.Translation.X, e.DeltaManipulation.Translation.Y);
                
                ((MatrixTransform)element.RenderTransform).Matrix = matrix;
    
            }
    
            private void image_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
            {
                //FrameworkElement element = (FrameworkElement)e.Source;
                //element.Opacity = 1;
    
            }
    


    Everyone Is NO.1

    2012年8月11日 3:59

全部回复