473,467 Members | 1,507 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Image-Button Class Visibility WPF

3 New Member
I am attempting to obtain class-data associated with a mouse-clicked ImageButton; which ImageButton is located within a Scollviewer wrapped WrapPanel and filled with numerous other ImageButtons. The problem is that although I can see the instance of the ImageButton selected "((PlanetClass)(fe))", and have visibility of the class instance's underlying data "((PlanetClass)(fe)).Content", I am unable to access any of the class's field data. The example below illustrates my intention.

Am I approaching this problem correctly (WrapPanel (wrapped in ScrollViewer)-> ImageButton-> FrameworkElement -> Instance of the Button -> Field Data)? If not, what would the best way be to access the ImageButton instance and associated data? Can anyone please point me in the right direction?

// WPF EventHandler at the container level:

Expand|Select|Wrap|Line Numbers
  1. <ScrollViewer ButtonBase.Click="SolarSystem_Click">
  2.  
  3. // Handles the ImageButton mouseClick event within the ScrollViewer wrapping the WrapPanel. 
  4. private void SolarSystem_Click(Object sender, RoutedEventArgs e) 
  5.     { 
  6.         FrameworkElement fe = e.OriginalSource as FrameworkElement; 
  7.         SelectedPlanet PlanetSelected = new SelectedPlanet(fe); 
  8.         MessageBox.Show(PlanetSelected.PlanetName); 
  9.     } 
  10.  
  11. // Used to initiate instance of ImageButton to access field data. 
  12. public SelectedPlanet(FrameworkElement fe) 
  13.     { 
  14.         return ((PlanetClass)(fe)); 
  15.     } 
  16.  
  17. // Class Data 
  18. public class PlanetClass 
  19.     { 
  20.         string planetName; 
  21.  
  22.         public PlanetClass(string planetName) 
  23.         { 
  24.             PlanetName = planetName; 
  25.         } 
  26.  
  27.         public string PlanetName 
  28.         { 
  29.             set { planetName = value; } 
  30.             get { return planetName; } 
  31.         } 
  32.     }
Apr 6 '10 #1
5 4279
tlhintoq
3,525 Recognized Expert Specialist
TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.
Apr 6 '10 #2
tlhintoq
3,525 Recognized Expert Specialist
I am unable to access any of the class's field data.
Unable to get the data, or you get the variable but it is blank?

I suspect the problem is here
Expand|Select|Wrap|Line Numbers
  1. public SelectedPlanet(FrameworkElement fe) 
  2.     { 
  3.         return ((PlanetClass)(fe)); 
  4.     }
You do realize this is not searching for an existing planet object, right? It is trying to cast an 'fe' object to become a new 'PlanetClass' object.

If the cast fails then you have no planet, and thus no PlanetName.
If it succeeds, it still makes a NEW PlanetObject using the default constructor (no parameters) and again you have no PlanetName.

Try this test. Change line 20 to give a default PlanetName and see if this is what you get.
Expand|Select|Wrap|Line Numbers
  1. string planetName = "Bob"; 
Now when you properly make a planet you are going to rename it, so "Bob" is overwritten. But if you cast into a new planet without giving it a name you will see it is still Planet Bob.
Apr 6 '10 #3
whunter31
3 New Member
tlhintoq -

Thank you for your quick reply. Actually I was just beginning to understand how ((PlanetClass)(fe)) wasn't returning the instance of the class, but attempting to recast the frameworkElement "fe" into the PlanetClass class. What confused me was that if I added ".Content" to the end of ((PlanetClass)(fe)), I could see the instance and it's data; however I could not actually address the instance to access it's data, as in "Planet.Name".

So, I guess I am back to square-one. Tlhintoq, would you possibly have any suggestion as to how to to access the data represented by an ImageButton, located in a ScrollViewer wrapped WrapPanel full of ImageButtons. Thanks once again.

Bill
Apr 6 '10 #4
tlhintoq
3,525 Recognized Expert Specialist
I have no idea what a WrapPanel even is.
I don't do WPF, if that helps.
Apr 6 '10 #5
whunter31
3 New Member
tlhintoq -

Thank you for your assistance. You've actually helped me realize where the problem lies.

Regards,
Bill
Apr 6 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Pierre Tremblay | last post by:
Hi! I am trying to display an image in my html document. The document contains the following line: <td class="Input"><img...
7
by: Paul Charlton-Thomson | last post by:
Hi! I have nearly cracked this and am stuck on the last bit. I am asking my visitors to rank 8 different items (a,b,c,d,e,f,g,h) from 1 to 10 and then I want to draw a pie chart of those values....
2
by: Tjerk | last post by:
Hello all, I have the script below to change an image depending on the date upto january it worked fine but then it just stopped working does anybody have an idea how I can make it work again or...
3
by: Kristof Thys | last post by:
Hello, I'm writing a ASP.net webservice wich will visualize an image, generated by another application. The generated image is a char*. I can transform this to a String*, but I want to view it...
7
by: lgbjr | last post by:
Hello All, I¡¯m using a context menu associated with some pictureboxes to provide copy/paste functionality. Copying the image to the clipboard was easy. But pasting an image from the clipboard...
15
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the...
5
by: Ricardo Furtado | last post by:
I'm trying, for a week or two, to create a procedure in order to rotate the image in any picturebox control in a cephalometry software. I've found a web site that shows how that can be done:...
1
by: helraizer1 | last post by:
Hi all, I have a dynamic image that picks out data from a dynamically created .line file. showimage.php(5) <?php include("linesfile.php5"); $linesDataFile = new DataFile("data.line");
1
by: bharathv6 | last post by:
i need to do is modify the image in memory like resizing the image in memory etc ... with out saving it disk as i have to return back the image with out saving it disk PIL supports the use of...
2
by: studentofknowledge | last post by:
For some unknown reason ie is placing images I have in a div in a weird way. One image is overlapping another but this problem is not occuring in mozilla. I have looked at my code over and over again...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.