1

I've tried to bind my image into the listbox i've created, yet it is just not working, can any1 help out with my problems so that i can actually bind the image into "ListBoxItem" as shown in the code below.

Code behind:

    public object ImageSource
    {
        get
        {
            Image finalImage = new Image();
            BitmapImage logo = new BitmapImage();
            logo.BeginInit();
            logo.UriSource = new Uri(@"/images/food1.bmp", UriKind.Relative);
            logo.EndInit();
            finalImage.Source = logo;

            return logo;
        }
    }

XAML:

    <ListBox Grid.ColumnSpan="2">
            <ListBox.Resources>
                <Style TargetType="{x:Type Image}">
                    <Setter Property="Width" Value="100"/>
                    <Setter Property="Height" Value="100"/>
                    <EventSetter Event="MouseLeftButtonDown" Handler="DragImage"/>
                </Style>
            </ListBox.Resources>
            <ListBoxItem>
                <Image Source="{Binding Path=ImageSource}" Width="197" Height="120" Margin="0,0,0,0"  />
            </ListBoxItem>
        </ListBox>
Jimmy
  • 13
  • 4

1 Answers1

0

could be a problem with the imagesource. check if this solves your problem.

Community
  • 1
  • 1
Markus Hütter
  • 7,796
  • 1
  • 36
  • 63
  • there is a little question here. If i wants to bind the image at this particular line "" as in my code above, which method can i use to do so? – Jimmy Feb 28 '11 at 02:52
  • i tried this "var uriSource = new Uri(@"/test;images/food1.bmp", UriKind.Relative); img.Source = new BitmapImage(uriSource);" with Am i doing the right thing? but somehow the image is not displayed. – Jimmy Feb 28 '11 at 03:05