Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF contextMenu control for bring forward and send backward
    primarykey
    data
    text
    <p>Having trouble with something here which I'm hoping is actually simple.</p> <p>I have a custom UserControl in WPF which allows me to display an image. When the program is running a user can add this UserControl as many times as they like to a canvas. In effect a simple image viewer where they can add and move images about. </p> <p>I would like to be able to right click these images open a contextMenu and then choose send backward of bring forward and the images would then change z order depending which menu choice was clicked.</p> <p>I have the user control set up with the contextMenu so I just need to know the code for changing the z order of this userControl...</p> <p>Any help is much appreciated :)</p> <pre><code>namespace StoryboardTool { /// &lt;summary&gt; /// Interaction logic for CustomImage.xaml /// &lt;/summary&gt; public partial class CustomImage : UserControl { private Point mouseClick; private double canvasLeft; private double canvasTop; public CustomImage() { InitializeComponent(); cusImageControl.SetValue(Canvas.LeftProperty, 0.0); cusImageControl.SetValue(Canvas.TopProperty, 0.0); } public void chooseImage() { OpenFileDialog ofd = new OpenFileDialog(); ofd.Title = "Choose Image to Add"; if (ofd.ShowDialog() == true) { BitmapImage bImage = new BitmapImage(); bImage.BeginInit(); bImage.UriSource = new Uri(ofd.FileName); bImage.EndInit(); image.Width = bImage.Width; image.Height = bImage.Height; image.Source = bImage; image.Stretch = Stretch.Fill; } } private void cusImageControl_LostMouseCapture(object sender, MouseEventArgs e) { ((CustomImage)sender).ReleaseMouseCapture(); } private void cusImageControl_MouseUp(object sender, MouseButtonEventArgs e) { ((CustomImage)sender).ReleaseMouseCapture(); cusImageControl.Cursor = Cursors.Arrow; } private void cusImageControl_MouseMove(object sender, MouseEventArgs e) { if ((((CustomImage)sender).IsMouseCaptured) &amp;&amp; (cusImageControl.Cursor == Cursors.SizeAll)) { Point mouseCurrent = e.GetPosition(null); double Left = mouseCurrent.X - mouseClick.X; double Top = mouseCurrent.Y - mouseClick.Y; mouseClick = e.GetPosition(null); ((CustomImage)sender).SetValue(Canvas.LeftProperty, canvasLeft + Left); ((CustomImage)sender).SetValue(Canvas.TopProperty, canvasTop + Top); canvasLeft = Canvas.GetLeft(((CustomImage)sender)); canvasTop = Canvas.GetTop(((CustomImage)sender)); } else if ((((CustomImage)sender).IsMouseCaptured) &amp;&amp; (cusImageControl.Cursor == Cursors.SizeNWSE)) { /*Point mouseCurrent = e.GetPosition(null); cusImageControl.Height = cusImageControl.canvasTop + mouseClick.Y; cusImageControl.Width = cusImageControl.canvasLeft + mouseClick.X; mouseClick = e.GetPosition(null);*/ } } private void cusImageControl_MouseDown(object sender, MouseButtonEventArgs e) { mouseClick = e.GetPosition(null); canvasLeft = Canvas.GetLeft(((CustomImage)sender)); canvasTop = Canvas.GetTop(((CustomImage)sender)); ((CustomImage)sender).CaptureMouse(); } private void ContextMenuBringForward_Click(object sender, RoutedEventArgs e) { MessageBox.Show("Bring Forward"); } private void ContextMenuSendBackward_Click(object sender, RoutedEventArgs e) { MessageBox.Show("Send Backward"); } private void ContextMenuMove_Click(object sender, RoutedEventArgs e) { cusImageControl.Cursor = Cursors.SizeAll; } private void ContextMenuResize_Click(object sender, RoutedEventArgs e) { cusImageControl.Cursor = Cursors.SizeNWSE; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload