locked
Border of Image RRS feed

  • Question

  • void currentImage_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
            {
                try
                {
                        Border brdr = new Border();
                        brdr.BorderThickness = new Thickness(1);
                        brdr.BorderBrush = new SolidColorBrush(Colors.Gray);
                        brdr.Background = new SolidColorBrush(Colors.Red);
                        brdr.CornerRadius = new CornerRadius(5);
                        brdr.Child = currentImage;
                 }
                catch (Exception ex)
                {
                    ;
                }
            }

     how can I Give border of the currentImage when Image is selected

    Tuesday, July 1, 2008 6:02 AM

Answers

  • Hi,

    void currentImage_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
            {

                Image img = sender as Image;

                Border brd = img.Parent as Border
            }

    I don't try it in VS2008.

    Tuesday, July 1, 2008 6:07 AM
  •  

    Dear It's not working
    Tuesday, July 1, 2008 7:06 AM
  •  Try to do like this, pre-set a border

    <Border x:Name="ImgBorder" Width="50" Height="50" Canvas.Left="-50" Canvas.Top="0" ...and any other stroke...etc/>

    when the event

    void currentImage_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        if (sender != null)
        {
        Image temp = sender as Image;
        ImgBorder.SetValue(Canvas.LeftProperty, Convert.ToDouble(temp.GetValue(Canvas.LeftProperty))-2);
        ImgBorder.SetValue(Canvas.TopProperty, Convert.ToDouble(temp.GetValue(Canvas.TopProperty))-2);
        }
    }

    Hopefully, I dont have any typing mistakes

    Tuesday, July 1, 2008 7:22 AM
  •  I suddenly think of another way to deal with it.

    Actually you can make a visualstate for the Image and put it into the Resources. And apply it to the Images.

    Tuesday, July 1, 2008 9:34 AM

All replies

  • Hi,

    void currentImage_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
            {

                Image img = sender as Image;

                Border brd = img.Parent as Border
            }

    I don't try it in VS2008.

    Tuesday, July 1, 2008 6:07 AM
  •  

    Dear It's not working
    Tuesday, July 1, 2008 7:06 AM
  •  Try to do like this, pre-set a border

    <Border x:Name="ImgBorder" Width="50" Height="50" Canvas.Left="-50" Canvas.Top="0" ...and any other stroke...etc/>

    when the event

    void currentImage_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        if (sender != null)
        {
        Image temp = sender as Image;
        ImgBorder.SetValue(Canvas.LeftProperty, Convert.ToDouble(temp.GetValue(Canvas.LeftProperty))-2);
        ImgBorder.SetValue(Canvas.TopProperty, Convert.ToDouble(temp.GetValue(Canvas.TopProperty))-2);
        }
    }

    Hopefully, I dont have any typing mistakes

    Tuesday, July 1, 2008 7:22 AM
  •  I suddenly think of another way to deal with it.

    Actually you can make a visualstate for the Image and put it into the Resources. And apply it to the Images.

    Tuesday, July 1, 2008 9:34 AM