Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <Grid>
- <Image x:Name="img" Stretch="None"></Image>
- <ItemsControl ItemsSource="{Binding RectItems, Source={x:Static vm:RectangleVM.instance}}">
- <ItemsControl.ItemsPanel>
- <ItemsPanelTemplate>
- <Canvas x:Name="cnvas" Width="{Binding ElementName=img, Path=ActualWidth}"
- Height="{Binding ElementName=img,Path=ActualHeight}"
- LayoutTransform="{Binding ElementName=img, Path=LayoutTransform}" ></Canvas>
- </ItemsPanelTemplate>
- </ItemsControl.ItemsPanel>
- <ItemsControl.ItemContainerStyle>
- <Style TargetType="ContentPresenter">
- <Setter Property="Canvas.Left" Value="{Binding X}"/>
- <Setter Property="Canvas.Top" Value="{Binding Y}"/>
- </Style>
- </ItemsControl.ItemContainerStyle>
- <ItemsControl.ItemTemplate>
- <DataTemplate>
- <Rectangle Width="{Binding Width}" Height="{Binding Height}" Stroke="Blue" />
- </DataTemplate>
- </ItemsControl.ItemTemplate>
- </ItemsControl>
- </Grid>
- <Window.Resources>
- <!-- MoveThumb Template -->
- <ControlTemplate x:Key="MoveThumbTemplate" TargetType="{x:Type resize:MoveThumb}">
- <Rectangle Fill="Transparent"/>
- </ControlTemplate>
- <!-- ResizeDecorator Template -->
- <ControlTemplate x:Key="ResizeDecoratorTemplate" TargetType="{x:Type Control}" >
- <Grid>
- <resize:ResizeThumb Height="3" Cursor="SizeNS" Margin="0 -4 0 0"
- VerticalAlignment="Top" HorizontalAlignment="Stretch"/>
- <resize:ResizeThumb Width="3" Cursor="SizeWE" Margin="-4 0 0 0"
- VerticalAlignment="Stretch" HorizontalAlignment="Left"/>
- <resize:ResizeThumb Width="3" Cursor="SizeWE" Margin="0 0 -4 0"
- VerticalAlignment="Stretch" HorizontalAlignment="Right"/>
- <resize:ResizeThumb Height="3" Cursor="SizeNS" Margin="0 0 0 -4"
- VerticalAlignment="Bottom" HorizontalAlignment="Stretch"/>
- <resize:ResizeThumb Width="7" Height="7" Cursor="SizeNWSE" Margin="-6 -6 0 0"
- VerticalAlignment="Top" HorizontalAlignment="Left"/>
- <resize:ResizeThumb Width="7" Height="7" Cursor="SizeNESW" Margin="0 -6 -6 0"
- VerticalAlignment="Top" HorizontalAlignment="Right"/>
- <resize:ResizeThumb Width="7" Height="7" Cursor="SizeNESW" Margin="-6 0 0 -6"
- VerticalAlignment="Bottom" HorizontalAlignment="Left"/>
- <resize:ResizeThumb Width="7" Height="7" Cursor="SizeNWSE" Margin="0 0 -6 -6"
- VerticalAlignment="Bottom" HorizontalAlignment="Right"/>
- </Grid>
- </ControlTemplate>
- <ControlTemplate x:Key="DesignerItemTemplate" TargetType="ContentControl">
- <Grid DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}">
- <resize:MoveThumb Template="{StaticResource MoveThumbTemplate}" Cursor="SizeAll"/>
- <Control Template="{StaticResource ResizeDecoratorTemplate}"/>
- <ContentPresenter Content="{TemplateBinding ContentControl.Content}"/>
- </Grid>
- </ControlTemplate>
- </Window.Resources>
- <Grid>
- <ScrollViewer>
- <Grid>
- <Image x:Name="img" Stretch="None"></Image>
- <ItemsControl ItemsSource="{Binding RectItems, Source={x:Static vm:RectangleVM.instance}}">
- <ItemsControl.ItemsPanel>
- <ItemsPanelTemplate>
- <Canvas x:Name="cnvas" Width="{Binding ElementName=img, Path=ActualWidth}"
- Height="{Binding ElementName=img,Path=ActualHeight}"
- LayoutTransform="{Binding ElementName=img, Path=LayoutTransform}" ></Canvas>
- </ItemsPanelTemplate>
- </ItemsControl.ItemsPanel>
- <ItemsControl.ItemContainerStyle>
- <Style TargetType="ContentPresenter">
- <Setter Property="Canvas.Left" Value="{Binding X}"/>
- <Setter Property="Canvas.Top" Value="{Binding Y}"/>
- </Style>
- </ItemsControl.ItemContainerStyle>
- <ItemsControl.ItemTemplate>
- <DataTemplate>
- <!--<Rectangle Width="{Binding Width}" Height="{Binding Height}" Stroke="Blue" />-->
- <ContentControl Width="{Binding Width}" BorderBrush="Transparent" BorderThickness="0"
- Height="{Binding Height}"
- Template="{StaticResource DesignerItemTemplate}">
- <Rectangle Stroke="Blue"/>
- </ContentControl>
- </DataTemplate>
- </ItemsControl.ItemTemplate>
- </ItemsControl>
- </Grid>
- </ScrollViewer>
- </Grid>
Add Comment
Please, Sign In to add comment