Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello

I'm looking for some guidance and help regarding Pathlistboxes. I currently have an class containing a string object for which i hope to have as a path to an image. My goal is to load a pathlistbox with images depending on the contents of an list of these custom objects.

What i'm not understanding how do i make the pathlistbox.itemsource reference my list of custom objects and display the appropriate image.

I've spent quite a bit of time searching for examples, but if anyone can point me in the right direction, that would be wonderful.

Thanks,

Ethan


** Revised **

Thanks for the help Venkatesh!

So i've tried to write some code building a pathlistbox, below i've added my xaml and cs code

The XAML looks like:
XML
<Page.Resources>
    <local:stringImageConverter x:Key="stringImageConverter"/>
    <DataTemplate x:Key="DataTemplateItemConverter">
            <Image Source="{Binding imageIndex, Converter={StaticResource stringImageConverter}}"></Image>
    </DataTemplate>
</Page.Resources>


XML
<ec:PathListBox x:Name="pathListBox" HorizontalAlignment="Right" Margin="0,372,66,71" Width="428">
    <ec:PathListBox.LayoutPaths>
        <ec:LayoutPath SourceElement="{Binding ElementName=path}"/>
    </ec:PathListBox.LayoutPaths>
</ec:PathListBox>


I'm using a converter to take my imageIndex int and add it to a string in this new class i've created

C#
public class stringImageConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        return "./Images/env" + value.ToString() + ".jpg";
    }

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}


then populate my list with objects as so. The first number after "ball" is my imageIndex for the object.

MIDL
public List<objObject> Items { get; set; } // ArrayList objectList = new ArrayList();
public pbox()
{
    this.InitializeComponent();
    Items = new List<objObject>();
    Items.Add(new objObject("Ball", 1,"Basic Game Object","Ball",1,0,0,0,0,0,"Static",1,1,1,1,"env"));
    Items.Add(new objObject("Box", 2, "Basic Game Object", "Box", 1, 0, 0, 0, 0, 0, "Static", 1, 1, 1, 1, "env"));
    Items.Add(new objObject("Border", 3, "Basic Game Object", "Border", 1, 0, 0, 0, 0, 0, "Static", 1, 1, 1, 1, "env"));
}


Currently all i get is an image on my page showing the path of my pathlistbox! Any further guidance, suggestions or help would be great!

Thanks again,

Ethan
Posted
Updated 8-Jul-11 20:52pm
v2
Comments
Venkatesh Mookkan 17-Jul-11 22:55pm    
Updated my answer. Please use "Add Comment" to ask further questions.

1 solution

I am sure you are taking about WPF/Silverlight. Use DataTemplate for the ListBoxItem. Write your DataTemplate to using the string path as ImageSource for a Image control.

It would be better post some code to make us understand the question better. Let me know.

Update 1:
ImageSource is not a String property. When you are using Converter you should convert the string to BitmapImage like below,

C#
ImageSource imgSource = new BitmapImage(imageUri);
return imgSource


here imageSource will be /<<AssemblyName>>;component/<<PATH>>

Eg:

/ProcessCenter;component/Images/Playbook.png


Here ProcessCenter.dll is the assembly and the image is located in Images folder inside the ProcessCenter project.

Mark it as answer if it is helpful
 
Share this answer
 
v3

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