locked
Pass string value to child window for use as photo URL RRS feed

  • Question

  • i am generating URLs that point to photos and am looking to see if I can pass those string values to a child window for use as the Source of an image.

    Here's an example of a URL I'm generating:
    string cphotoURL1 = @"http://xxx.xxx.xxx.xx/Data/Chevy/Vehicles/" + selectedVIN + "/" + selectedVIN + "-01.jpg";

    from the child window, here's the XAML for the image:
      <Image x:Name="image" HorizontalAlignment="Left" Height="255" Margin="23,22,0,0" VerticalAlignment="Top" Width="340" Stretch="Fill" Source= "cphotoURL1" />

    I have tried removing the quotes but the XAML fails. Is there a way to use the string value as the image source?

    thanks!


    slowly getting my mind around .NET...
    Thursday, February 10, 2011 8:00 PM

Answers

  • To fix this specific error, change "new Vehicle_Details();" to "new Vehicle_Details(dphotoURL1);"

    You can then remove the next line, as it is redundant. My other post has more details on what you probably want to have eventually.

    • Marked as answer by angus454 Friday, February 11, 2011 3:01 PM
    Friday, February 11, 2011 3:00 PM
    Moderator

All replies

  • There are quite a few ways you can do this, one simple way is something like:

     

    1. On your child window class, the one with the image, define a static string property

    2. When you create the uri string, set the static property

    3. In the constructor for your child window, use the static property to set the source value of the image (this.image.Source = new Uri(MyChildWindowClass.UriString))

    More advanced methods include databinding the Image's source property to a property on your class, but then you need to set that property as you create the ChildWindow.

     

    Hope that helps, let me know if you need more help implementing this. If you do, please post more of your code so I can give you a more specific answer.

    Friday, February 11, 2011 2:43 PM
    Moderator
  • OK, if you are doing this all in code, it makes it a bit easier. I had assumed a lot of this was being done in xaml.

    From your example above, the error is saying that when you try to construct a Vehicle_Details object, you try to use a constructor with 0 arguments, you only provided a constructor with 1 argument.

     

    Vehicle_Details childControl = new Vehicle_Details(dhPhotoUrl1);
    
    childControl.Show();
    

     

    Then in the child control:

     

    public Vehicle_Details(string value)
    
    {
    
    InitializeComponent();
    
    this.txtValue.Text = value; // This would be the line that says this.Image.Source = new Uri(value, UriKind.Absolute);
    
    }
    

     


    Friday, February 11, 2011 2:58 PM
    Moderator
  • Thank you for answering, let me try the code again... here's the Parent and then the Child code...

    public partial class Vehicle_Details : ChildWindow
        {
      
     public string Value { get; set; }
            
      
      
            public Vehicle_Details(string value)
            {
                InitializeComponent();
       this.Value = value;
            }

            private void OKButton_Click(object sender, RoutedEventArgs e)
            {
                this.txtValue.Text = this.Value.ToString();
            }

            private void CancelButton_Click(object sender, RoutedEventArgs e)
            {
                this.DialogResult = false;
            }
        }

    Here's the parent window code.


            private void dgDodge_SelectionChanged(object sender, SelectionChangedEventArgs e)
            {

                var cell = dgDodge.CurrentColumn.GetCellContent(dgDodge.SelectedItem);
       TextBlock tb = cell as TextBlock;
               
       string selectedVIN = tb.Text;
       txtSelectedValue.Text = tb.Text;
       
       // dodge photo urls
       
       string dphotoURL1 = @"http://xxx.xxx.xxx.xxx/Data/DodgeChrysler/Vehicles/" + selectedVIN + "/" + selectedVIN + "-01.jpg";

    Vehicle_Details childControl = new Vehicle_Details();    ********** this is where I'm getting the error ************
       childControl.Value = dphotoURL1;
       childControl.Show();


    This is the error "'DOAN_DAILY_USED_INVENTORY.Vehicle_Details' does not contain a constructor that takes 0 arguments"


    slowly getting my mind around .NET...
    Friday, February 11, 2011 2:58 PM
  • To fix this specific error, change "new Vehicle_Details();" to "new Vehicle_Details(dphotoURL1);"

    You can then remove the next line, as it is redundant. My other post has more details on what you probably want to have eventually.

    • Marked as answer by angus454 Friday, February 11, 2011 3:01 PM
    Friday, February 11, 2011 3:00 PM
    Moderator
  • thank you! much appreciated!
    slowly getting my mind around .NET...
    Friday, February 11, 2011 3:01 PM