Hi all,
I am currently stuck at the point in the following code where its bold. I am trying to extract the name of the instance of myImage depending on whether I've clicked it or not:
Basically the messagebox displays nothing. How can I extract the name of the myImage control that has been clicked?Code:Class Window1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click Dim myImage As New Image() myImage.Width = 32 Dim myBitmapImage As New BitmapImage() myBitmapImage.BeginInit() myBitmapImage.UriSource = New Uri("Sade.jpg", UriKind.Relative) myBitmapImage.DecodePixelWidth = 32 myBitmapImage.EndInit() Dim BlankTile As New BitmapImage() BlankTile.BeginInit() BlankTile.UriSource = New Uri("BlankTile.jpg", UriKind.Relative) BlankTile.DecodePixelWidth = 32 BlankTile.EndInit() Dim Col As Integer = UniformGrid1.Columns NameScope.SetNameScope(UniformGrid1, New NameScope()) For i = 1 To UniformGrid1.Rows For j = 1 To UniformGrid1.Columns Dim myImage1 As New Image myImage1.Width = 32 Dim X, Y As Integer X = j Y = i myImage1.SetValue(myImage1.NameProperty, "T" & Y.ToString("D3") & X.ToString("D3")) myImage1.Name = "T" & Y.ToString("D3") & X.ToString("D3") UniformGrid1.Children.Add(myImage1) UniformGrid1.RegisterName("T" & Y.ToString("D3") & X.ToString("D3"), UniformGrid1.Children.Item(Item(i, j, Col))) myImage1.Source = BlankTile AddHandler myImage1.MouseUp, AddressOf TileClicked Next Next Dim Tile As New Image Tile = UniformGrid1.FindName("T001001") Tile.Source = myBitmapImage Tile = UniformGrid1.FindName("T005005") Tile.Source = myBitmapImage End Sub Private Sub TileClicked(ByVal sender As Object, ByVal e As RoutedEventArgs) MessageBox.Show(Me.Name.ToString) End Sub Function Item(ByVal Row As Integer, ByVal Column As Integer, ByVal NoOfColumns As Integer) As Integer Return ((Row - 1) * NoOfColumns) + Column - 1 End Function End Class




,
Reply With Quote