路径列表框和绑定数据

路径列表框和绑定数据

本文介绍了路径列表框和绑定数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我正在寻找有关Pathlistboxes的一些指导和帮助.我目前有一个包含字符串对象的类,希望将其作为图像的路径.我的目标是根据这些自定义对象列表的内容为图像加载路径列表框.

我不了解如何使pathlistbox.itemsource引用我的自定义对象列表并显示适当的图像.

我花了很多时间搜索示例,但是如果有人可以指出正确的方向,那将是很棒的.

谢谢,

伊森


**修订**

感谢Venkatesh的帮助!

因此,我尝试编写一些构建路径列表框的代码,在下面添加了我的xaml和CS代码

XAML看起来像:

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:

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





<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>



我正在使用转换器将我的imageIndex int并将其添加到我创建的这个新类中的字符串中



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

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();
    }
}



然后用对象填充我的列表. "ball"之后的第一个数字是我对该对象的imageIndex.



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

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"));
}



目前,我所获得的只是页面上的一张图片,该图片显示了pathlistbox的路径!任何进一步的指导,建议或帮助都将非常有用!

再次感谢,

Ethan



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

推荐答案

ImageSource imgSource = new BitmapImage(imageUri);
return imgSource



此处imageSource将为/<<AssemblyName>>;component/<<PATH>>

例如:



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

Eg:

/ProcessCenter;component/Images/Playbook.png



ProcessCenter.dll是程序集,图像位于ProcessCenter 项目内的Images文件夹中.

如果有帮助,请将其标记为答案



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


这篇关于路径列表框和绑定数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 05:17