2012-05-03 122 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