I want to add image at run-time to a RadTreeViewItem in WPF.
9 Answers, 1 is accepted
There are manu ways to acomplish this. However, since I am note reallt sure what are the requirement sof your scenario, I will suggest a cauple of approaches.
First, if you have a RadTreeView that is databound to a business object, you can add a property of type Uri to that business object. Then in the ItemTemplate for the RadTreeViewItems you can add an Image with Source databound to the value of the Uri property of your object.
Another approach is to use the DefaultImageSrc, ExpandedImageSrc and SelectedImageSrc properties of the RadTreeViewItem and set them in code behind:
item.DefaultImageSrc =
"images/RedIcon.png"
;
Take a look at the project and let me know if this is what you had in mind.
Sincerely yours,
Tina Stancheva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
There are many ways to accomplish this. However, since I am note really sure what are the requirements of your scenario, I will suggest a couple of approaches.
First, if you have a RadTreeView that is databound to a business object, you can add a property of type Uri to that business object. Then in the ItemTemplate for the RadTreeViewItems you can add an Image with Source databound to the value of the Uri property of your object.
Another approach is to use the DefaultImageSrc, ExpandedImageSrc and SelectedImageSrc properties of the RadTreeViewItem and set them in code behind:
item.DefaultImageSrc =
"images/RedIcon.png"
;
Take a look at the project and let me know if this is what you had in mind.
Sincerely yours,
Tina Stancheva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
I have a folder named images and I assign my image path in code-behind side
myRadTreeViewItem.DefaultImageSrc =
"images/add.png";
myRadTreeViewItem.ExpandedImageSrc =
"images/edit.png";
myRadTreeViewItem.SelectedImageSrc =
"images/editpaste.png";
and at Xaml side I assign also RadTreeView control's ImagesBaseDir property to
ImagesBaseDir="/images/";
but still it is not working.
When you store all your images for the TreeView into a single folder you can use the ImagesBaseDir property of the RadTreeView to set the location of this folder. Then when settings the DefaultImagesSrc, ExpandedImageSrc, SelectedImageSrc properties of the RadTreeViewItem you will need to set only the image name, not the entire path to the image.
Therefore, in your case you can either set the ImagesBaseDir to "/" and keep the values of the DefaultImagesSrc, ExpandedImageSrc, SelectedImageSrc properties or you can set the DefaultImagesSrc, ExpandedImageSrc, SelectedImageSrc to: "add.png", "edit.png", "editpaste.png" accordingly and set the ImagesBaseDir to ImagesBaseDir="/images/", like you do.
Give it a try and let me know if it works for you.
Greetings,
Tina Stancheva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Actually, I add my images to RadTreeViewItem at runtime, could it be a reason for the problem? Cause it is still the same. At Xaml side RadTreeView property still like that -> ImagesBaseDir="/images/"
RadTreeViewItem rti;
for (int i = 0; i < ParentCount; i++)
{
rti =
new RadTreeViewItem();
rti.Header = "header";
for (int j = 0; j < ChildCount; j++)
{
rti.Items.Add("ChildName");
}
rti.DefaultImageSrc =
"add.png";
rti.ExpandedImageSrc =
"edit.png";
rti.SelectedImageSrc =
"editpaste.png";
myRadTreeView.Items.Add(rti);
}
the best will be if you send us your project so we can take a look at it. Thanks!
All the best,
Valentin.Stoychev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
I had been written RadTreeView property with a wrong assignment -> IsVirtualizing = True, I changed its property to False, and now I can assign images to my RadTreeViewItems.
Thank you for your interest.
Best Regards,
Emre Andıç.
We are glad that you got it working.
Let us know if we can further assist you.
Best wishes,
Tina Stancheva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
thank you so much.
Best Regards,
Emre Andıç.