❔ WPF Binding TreeViewItem name to string, and falling back to another data context property
I made a little file explorer app and I wanted to try and allow folders to have no names; The data context contains a property string called
Name
and I bound the string to a text block in my TreeViewItem's style which works fine. But in the event that a folder's name is null or empty, i want it to default to something like Folder of ? items
, where ? would be how many items it contains (i'm using an observable collection to store children items in the data context).
I tried using a converter and binding to the name, but i have no way of passing the data context to the converter to access the data context. Is there a way around this?5 Replies
this is the text block I have currently, but i wanna somehow pass the data context to the converter
and then this is the converter code that would run
I might just add a string to my data context called "FolderNameFinal" or something, which gets modifed when a child is added/removed or the name changes
don't use a converter for that
just make another property
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.