Guest User

Untitled

a guest
Nov 22nd, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.28 KB | None | 0 0
  1. <Grid>
  2.  
  3.  
  4.  
  5. <Image x:Name="img" Stretch="None"></Image>
  6.  
  7. <ItemsControl ItemsSource="{Binding RectItems, Source={x:Static vm:RectangleVM.instance}}">
  8. <ItemsControl.ItemsPanel>
  9. <ItemsPanelTemplate>
  10.  
  11.  
  12.  
  13.  
  14. <Canvas x:Name="cnvas" Width="{Binding ElementName=img, Path=ActualWidth}"
  15. Height="{Binding ElementName=img,Path=ActualHeight}"
  16. LayoutTransform="{Binding ElementName=img, Path=LayoutTransform}" ></Canvas>
  17.  
  18.  
  19. </ItemsPanelTemplate>
  20. </ItemsControl.ItemsPanel>
  21. <ItemsControl.ItemContainerStyle>
  22. <Style TargetType="ContentPresenter">
  23. <Setter Property="Canvas.Left" Value="{Binding X}"/>
  24. <Setter Property="Canvas.Top" Value="{Binding Y}"/>
  25. </Style>
  26. </ItemsControl.ItemContainerStyle>
  27. <ItemsControl.ItemTemplate>
  28. <DataTemplate>
  29. <Rectangle Width="{Binding Width}" Height="{Binding Height}" Stroke="Blue" />
  30.  
  31. </DataTemplate>
  32. </ItemsControl.ItemTemplate>
  33. </ItemsControl>
  34. </Grid>
  35.  
  36. <Window.Resources>
  37. <!-- MoveThumb Template -->
  38. <ControlTemplate x:Key="MoveThumbTemplate" TargetType="{x:Type resize:MoveThumb}">
  39. <Rectangle Fill="Transparent"/>
  40. </ControlTemplate>
  41.  
  42.  
  43. <!-- ResizeDecorator Template -->
  44. <ControlTemplate x:Key="ResizeDecoratorTemplate" TargetType="{x:Type Control}" >
  45. <Grid>
  46. <resize:ResizeThumb Height="3" Cursor="SizeNS" Margin="0 -4 0 0"
  47. VerticalAlignment="Top" HorizontalAlignment="Stretch"/>
  48. <resize:ResizeThumb Width="3" Cursor="SizeWE" Margin="-4 0 0 0"
  49. VerticalAlignment="Stretch" HorizontalAlignment="Left"/>
  50. <resize:ResizeThumb Width="3" Cursor="SizeWE" Margin="0 0 -4 0"
  51. VerticalAlignment="Stretch" HorizontalAlignment="Right"/>
  52. <resize:ResizeThumb Height="3" Cursor="SizeNS" Margin="0 0 0 -4"
  53. VerticalAlignment="Bottom" HorizontalAlignment="Stretch"/>
  54. <resize:ResizeThumb Width="7" Height="7" Cursor="SizeNWSE" Margin="-6 -6 0 0"
  55. VerticalAlignment="Top" HorizontalAlignment="Left"/>
  56. <resize:ResizeThumb Width="7" Height="7" Cursor="SizeNESW" Margin="0 -6 -6 0"
  57. VerticalAlignment="Top" HorizontalAlignment="Right"/>
  58. <resize:ResizeThumb Width="7" Height="7" Cursor="SizeNESW" Margin="-6 0 0 -6"
  59. VerticalAlignment="Bottom" HorizontalAlignment="Left"/>
  60. <resize:ResizeThumb Width="7" Height="7" Cursor="SizeNWSE" Margin="0 0 -6 -6"
  61. VerticalAlignment="Bottom" HorizontalAlignment="Right"/>
  62. </Grid>
  63. </ControlTemplate>
  64.  
  65. <ControlTemplate x:Key="DesignerItemTemplate" TargetType="ContentControl">
  66. <Grid DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}">
  67. <resize:MoveThumb Template="{StaticResource MoveThumbTemplate}" Cursor="SizeAll"/>
  68. <Control Template="{StaticResource ResizeDecoratorTemplate}"/>
  69. <ContentPresenter Content="{TemplateBinding ContentControl.Content}"/>
  70. </Grid>
  71. </ControlTemplate>
  72. </Window.Resources>
  73. <Grid>
  74.  
  75. <ScrollViewer>
  76.  
  77. <Grid>
  78.  
  79.  
  80.  
  81. <Image x:Name="img" Stretch="None"></Image>
  82.  
  83. <ItemsControl ItemsSource="{Binding RectItems, Source={x:Static vm:RectangleVM.instance}}">
  84. <ItemsControl.ItemsPanel>
  85. <ItemsPanelTemplate>
  86.  
  87.  
  88.  
  89.  
  90. <Canvas x:Name="cnvas" Width="{Binding ElementName=img, Path=ActualWidth}"
  91. Height="{Binding ElementName=img,Path=ActualHeight}"
  92. LayoutTransform="{Binding ElementName=img, Path=LayoutTransform}" ></Canvas>
  93.  
  94.  
  95. </ItemsPanelTemplate>
  96. </ItemsControl.ItemsPanel>
  97. <ItemsControl.ItemContainerStyle>
  98. <Style TargetType="ContentPresenter">
  99. <Setter Property="Canvas.Left" Value="{Binding X}"/>
  100. <Setter Property="Canvas.Top" Value="{Binding Y}"/>
  101. </Style>
  102. </ItemsControl.ItemContainerStyle>
  103. <ItemsControl.ItemTemplate>
  104. <DataTemplate>
  105. <!--<Rectangle Width="{Binding Width}" Height="{Binding Height}" Stroke="Blue" />-->
  106. <ContentControl Width="{Binding Width}" BorderBrush="Transparent" BorderThickness="0"
  107.  
  108. Height="{Binding Height}"
  109.  
  110.  
  111. Template="{StaticResource DesignerItemTemplate}">
  112. <Rectangle Stroke="Blue"/>
  113. </ContentControl>
  114. </DataTemplate>
  115. </ItemsControl.ItemTemplate>
  116. </ItemsControl>
  117. </Grid>
  118. </ScrollViewer>
  119. </Grid>
Add Comment
Please, Sign In to add comment