图像(图标)应显示在树视图左侧的数据库中。 [英] Image (icon) should display from database on the leftside of treeview.

查看:72
本文介绍了图像(图标)应显示在树视图左侧的数据库中。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个树视图,它是数据库中的类别和子类别的绑定。



我想在树视图的左侧显示一个图标(图像)。例如,在树形视图中,我有类别,例如amana工具作为父节点,路由器位作为amana工具的子节点。因此,在数据库中我有amana工具的图标以及路由器位的图标。现在,我只能在treeview中显示类别(amana工具)。但是,我需要左侧应显示相关类别的图标,然后显示类别名称(amana工具)。





注意:图标应该从数据库绑定,但它不应该是静态图标,因为我需要显示超过100个类别和数据库中存在的图标。



请帮帮我。

I have created a treeview, which is binding categories and subcategories from database.

I want to display an icon (image) on left side of the treeview. For example, in treeview I have categories such as amana tool as a parent node and the router bits as child node of amana tool. So, in database I have icon of amana tool as well as icon of router bits. Now, I am able to show categories (amana tool) only in treeview. But, I need that left side should show the icon of the related categories and then categories name(amana tool).


Note: The icon should bind from database but it should not be static icon because I need to show more than 100 categories and the icon existing in database.

Please help me out.

推荐答案

您好,

您必须将树视图项定义为单独的类。在该类中定义属性,如header,url和image source。请参阅下面的代码以了解更多信息。

将树视图项定义为类名称MenuItem。

代码:



Hi,
You have to define a tree view item as a seperate class. In that class define propertys like header, url and image source. see below code for more understand.
Define a tree view item as class name MenuItem.
Code:

MenuItem Class:
public class MenuItem
    {
        public string Header { get; set; }
        public string Url { get; set; }
        public BitmapImage ImageSource { get; set; }
        public List<menuitem> SubMenuItems { get; set; }
    }

List <menuitem> MenuItems = new List<menuitem>();
MenuItems.Add(
                    new MenuItem()
                    {
                        Header = "Display Name",
                        Url = "NavigationUrl",
                        ImageSource = new System.Windows.Media.Imaging.BitmapImage(new Uri("ur image url from database", UriKind.RelativeOrAbsolute)),
                                            });
//Bind menitems list to ur treeview 
tvLeftMenu.ItemsSource = MenuItems;



谢谢

Anil


Thanks
Anil


这篇关于图像(图标)应显示在树视图左侧的数据库中。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆