Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <Window x:Class="WpfApplication2.MainWindow"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
- xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
- xmlns:local="clr-namespace:WpfApplication2"
- mc:Ignorable="d"
- Title="MainWindow" Height="350" Width="525">
- <Grid Name="grd">
- <Canvas Name="cnvs" HorizontalAlignment="Center" Height="1276" VerticalAlignment="Center" Width="1550"/>
- <Button x:Name="button" Content="Button" HorizontalAlignment="Left" VerticalAlignment="Top" Width="143" Height="63" Click="button_Click" RenderTransformOrigin="0.5,0.5"/>
- </Grid>
- </Window>
- private void button_Click(object sender, RoutedEventArgs e)
- {
- Point position = button.TranslatePoint(new Point(0, 0), (VisualTreeHelper.GetParent(cnvs) as UIElement));
- grd.Children.Remove(button);
- cnvs.Children.Add(button);
- Canvas.SetLeft(button, position.X);
- Canvas.SetTop(button, position.Y);
- }
- Point position = grd.TranslatePoint(new Point(0, 0), cnvs);
- Point position = button.TranslatePoint(new Point(0, 0), cnvs);
Add Comment
Please, Sign In to add comment