ItemsControl中的Adorner

时间:2017-09-26 04:36:16

标签: wpf canvas mvvm itemscontrol adorner

我在ItemsControl中使用Canvas,可以绘制矩形,圆形等形状。我想调整大小并移动绘制的形状。我尝试过使用装饰器,但没有找到在ItemsControl中使用装饰器的方法,这可能吗?

                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <zc:ZoomableCanvas Loaded="Canvas_Loaded"
                                    RealizationLimit="1000" 
                                    RealizationRate="10"
                                    RealizationPriority="Background"
                                    ApplyTransform="False"
                                    Scale="{Binding ZoomableCanvas.Scale}"
                                    Offset="{Binding ZoomableCanvas.Offset}" ClipToBounds="True"
                                    Width="{Binding ZoomableCanvas.ActualWidth}"
                                    Height="{Binding ZoomableCanvas.ActualHeight}"
                                    >
                        </zc:ZoomableCanvas>
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>

1 个答案:

答案 0 :(得分:1)

答案可能有点迟了,但我写这篇文章以供将来参考。

您使用的Canvas只能在AdornerDecorator内显示装饰者。试试这个:

<AdornerDecorator>
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <zc:ZoomableCanvas Loaded="Canvas_Loaded"
                               RealizationLimit="1000" 
                               RealizationRate="10"
                               RealizationPriority="Background"
                               ApplyTransform="False"
                               Scale="{Binding ZoomableCanvas.Scale}"
                               Offset="{Binding ZoomableCanvas.Offset}" 
                               ClipToBounds="True"
                               Width="{Binding ZoomableCanvas.ActualWidth}"
                               Height="{Binding ZoomableCanvas.ActualHeight}"
                               >
            </zc:ZoomableCanvas>
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
</AdornerDecorator>

我希望这有帮助!