2012-05-03 85 views
1

我有一个图像控件。在运行时单击图像时,它应该作为孩子添加到网格中。我已经实现了这一点。点击图像时围绕图像

我现在的要求是当图像(现在在一个网格内)被挖掘时我需要一个图像边框。我怎样才能做到这一点?

我加入里面挖掘图像下面的代码,但不能看到边框

Border b = new Border(); 
b.BorderThickness = new Thickness(4); 
img1 = new Image(); 
img1.MaxHeight = 300; 
img1.MaxWidth = 500; 
b.Child = img1; 
img1.Source = new BitmapImage((new Uri(imgPath, UriKind.RelativeOrAbsolute))); 
grid1.Children.Add(b); 

回答

2

相反滴速的图像作为网格单元孩子,创建一个Border对象,并把图像里面的内容。

最初,边框可以具有BorderBrush透明和厚度= 1或其他。然后,将Tapped事件添加到图像以修改边框笔刷颜色。

根据上面的代码,你需要像

img1.Tapped += delegate(object sender, EventArgs e) 
{ 
    ((sender as Image).Parent as Border).BorderBrush = Brushes.Blue; 
}); 
+0

与大家分享您的烃源代码给你一个活生生的例子 – 2012-05-03 03:40:55

+0

我认为使用[螺纹](http://msdn.microsoft.com/ en-us/library/windows/apps/windows.ui.xaml.uielement.tapped.aspx)事件,而不是MouseEnter和MouseLeave,将与OP所要求的更紧密地匹配。 –

+0

@JaimeOlivares请找到上面的代码。 – spiharsh