user3493747
user3493747

Reputation: 13

Parameter to an image

How to add a parameter for an image to this variable?

var selectionDisplay = new SelectionDisplay(button.Label as string);

Thanks in advance!

EDIT:

I have this set of images and their respective code below (see pic1)

This is where the program gets the images to be displayed. The code for the buttons is this one:

var files = Directory.GetFiles(@".\GalleryImages");
                     foreach (var file in files)
                     {
                             FileInfo fileInfo = new FileInfo(file);
                             BitmapImage bi = new BitmapImage();
                             bi.BeginInit();
                             bi.UriSource = new Uri(file, UriKind.Relative);
                             bi.EndInit();
                             var button = new KinectTileButton
                             {
                                     Label = System.IO.Path.GetFileNameWithoutExtension(file),
                                     Background = new ImageBrush(bi)
                             };
                             this.wrapPanel.Children.Add(button);
                     }

This is where the program gets the images to be displayed. The code for the buttons is this one:

private void KinectTileButtonclick(object sender, RoutedEventArgs e)
     {
             var button = (KinectTileButton)e.fake_fake_fakeource;
             var selectionDisplay = new SelectionDisplay(button.Label as string);
             this.kinectRegionGrid.Children.Add(selectionDisplay);
             e.Handled = true;

Right now, when i click on of the images, the SelectionDisplay window pops up, which look like this (see pic2). What i want is that when I click an image the SelectionDisplay window should open with the respective image... meaning that if I click on the image with a dog, the window should open with the dog's image, not with other image.

I hope I've made myself clear and that you can help me.

http://i58.tinypic.com/8zl6h3.jpg http://i57.tinypic.com/208fosy.png

Upvotes: 1

Views: 98

Answers (2)

user3493747
user3493747

Reputation: 13

is this the constructor you are talking about? is this where i should make changes? should i add something after "string itemid"?

public SelectionDisplay(string itemId)
    {
        this.InitializeComponent();

        this.messageTextBlock.Text = string.Format(CultureInfo.CurrentCulture,Properties.Resources.SelectedMessage,itemId);
    }

Upvotes: 1

BradleyDotNET
BradleyDotNET

Reputation: 61349

I see two approaches:

  1. Just pass the image brush in your constructor. Its view->view, so you aren't breaking MVVM (and it looks like you aren't using that pattern anyways).

    new SelectionDisplay(button.Label, button.Background);
    
  2. Set the path as the "tag" of the button. The tag property is an object you can put whatever you want into (the framework does not use it, and so it is included for this very purpose). Then just pass the string to SelectionDisplay, and instantiate the image just like you are doing for the button:

    var button = new KinectTileButton
    {
         Label = System.IO.Path.GetFileNameWithoutExtension(file),
         Background = new ImageBrush(bi),
         Tag = file
    };
    var selectionDisplay = new SelectionDisplay(button.Label as string, button.Tag as string);
    

FrameworkElement.Tag on MSDN (Note that Button derives from FrameworkElement, as do all controls, so it automatically has it as well!)

UPDATE I see that SelectionDisplay is a UserControl in your project, so you just need to change its constructor to look like:

Numbers match above:

  1. SelectionDisplay(string labelText, ImageBrush sourceImage)

  2. SelectionDisplay(string labelText, string imagePath)

That is the source of the error you are getting, you have to modify the constructor to take the new parameter.

Please let me know if I can clarify anything.

Upvotes: 0

Related Questions