I am adding image to the radtreeviewitem from resources programatically using the below code.
我使用下面的代码从参考资料中程序化地向radtreeviewitem添加映像。
"/myAssembley;component/Resources/image1.png"
and the image is displaying successfully. Now i need to add another image which needs to be displayed next to the first image in the radtreeviewitem.
图像显示成功。现在我需要添加另一个图像,它需要显示在radtreeviewitem的第一个图像旁边。
how to achieve it.?
如何实现它。?
Like the below image i need my treeviewitem to display a folder icon and a red square icon in a single treeview item.
像下面的图片一样,我需要我的treeviewitem在一个treeview项中显示一个文件夹图标和一个红方图标。
2 个解决方案
#1
4
If you do not have data binding and you are using RadTreeViewItems directly you can add the additional image in the Header of the item. For example:
如果您没有数据绑定,并且正在直接使用RadTreeViewItems,那么您可以在项目的头中添加额外的图像。例如:
var stackPanel = new StackPanel() { Orientation = System.Windows.Controls.Orientation.Horizontal };
var image1 = new Image() { Source = image1Path };
var image2 = new Image() { Source = image2Path };
var textBlock = new TextBlock() { Text = itemHeader };
stackPanel.Children.Add(image1);
stackPanel.Children.Add(image2);
stackPanel.Children.Add(textBlock);
var treeViewItem = new RadTreeViewItem()
{
Header = stackPanel,
};
It Works.
它的工作原理。
#2
2
The proper way would be to create a DataTemplate with a grid or horizontal stackpanel. Put two images inside and in your model two Image Sources that you can bind too. Telerik doesn't have the best track record using the MVVM pattern, but the TreeView control is pretty decent with binding. If you need help with the model and the datatemplate, post some of your code here and we can work on it.
正确的方法是使用网格或水平堆栈面板创建一个DataTemplate。在模型内部和模型中放入两个可以绑定的图像源。Telerik没有使用MVVM模式的最佳跟踪记录,但是TreeView控件在绑定方面相当不错。如果您需要对模型和datatemplate的帮助,请在这里发布一些代码,我们可以对此进行研究。
#1
4
If you do not have data binding and you are using RadTreeViewItems directly you can add the additional image in the Header of the item. For example:
如果您没有数据绑定,并且正在直接使用RadTreeViewItems,那么您可以在项目的头中添加额外的图像。例如:
var stackPanel = new StackPanel() { Orientation = System.Windows.Controls.Orientation.Horizontal };
var image1 = new Image() { Source = image1Path };
var image2 = new Image() { Source = image2Path };
var textBlock = new TextBlock() { Text = itemHeader };
stackPanel.Children.Add(image1);
stackPanel.Children.Add(image2);
stackPanel.Children.Add(textBlock);
var treeViewItem = new RadTreeViewItem()
{
Header = stackPanel,
};
It Works.
它的工作原理。
#2
2
The proper way would be to create a DataTemplate with a grid or horizontal stackpanel. Put two images inside and in your model two Image Sources that you can bind too. Telerik doesn't have the best track record using the MVVM pattern, but the TreeView control is pretty decent with binding. If you need help with the model and the datatemplate, post some of your code here and we can work on it.
正确的方法是使用网格或水平堆栈面板创建一个DataTemplate。在模型内部和模型中放入两个可以绑定的图像源。Telerik没有使用MVVM模式的最佳跟踪记录,但是TreeView控件在绑定方面相当不错。如果您需要对模型和datatemplate的帮助,请在这里发布一些代码,我们可以对此进行研究。