Click here to Skip to main content
15,891,850 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I don't know what is the problem with my code I add an Image to myGrid
and name my image and when I want to find my Image by name, here is my code:

I first do :
MIDL
myControlIcons[p, q].Source = myBitmapImage;
                   myControlIcons[p, q].Name = "ControlIcon_" + p.ToString() + "_" + q.ToString();
                   myGrid.Children.Add(myControlIcons[p, q]);

and then here when I got problem
C#
object myFE = myGrid.FindName("ControlIcon_" + p.ToString() + "_" + q.ToString());
               if (myFE != null)
                   MessageBox.Show("it is framework element");
               if(myFE == null)
                   MessageBox.Show("it is not framework element");
Posted
Updated 12-Dec-10 19:37pm
v2
Comments
Venkatesh Mookkan 13-Dec-10 1:31am    
I don't understand why are you naming your control when you are adding to the Grid.

Check if Grid.Children.Count > 0 you use FindName function.
cppwxwidgets 13-Dec-10 2:30am    
I name my Control and add it to my Grid in a method
then use that name in other methods that don't have reference to that control

1 solution

I found the answer myself
the answer is that all names should be registered so the solution:
Grid myGrid = new Grid();
Image myImage = new Image();
myImage.Name = "myImage";

//here 
NameScope.SetNameScope(myGrid, new NameScope());

myGrid.RegisterName(myImage.Name, myImage);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900