I have a combobox that displays items from an ObservableCollection (which contains several directory links. I then have several treeviews and datatables, all of which needs to reference the directories based on the combobox selection. I know I've seen a similar question in the past just haven't been able to find it since!! Any direction would be appreciated!
For example the collection's contents are:
public class ProjectThread
{
public String projectName { get; set; }
public String Directory1 { get; set; }
public String Directory2 { get; set; }
public String Directory3 { get; set; }
}
Now I'm trying to figure out how to retrieve multiple value paths from a single combobox selection:
<ComboBox x:Name="comboBox"
HorizontalAlignment="Left"
ItemsSource="{Binding Items}"
DisplayMemberPath="projectName"
SelectedValuePath="Directory1"/> (**How to reference multiple?)
Here's how my treeviews are being initialized:
public MainWindow()
{
InitializeComponent();
this.ListDirectory(treeView1, **unsure how to reference directory from combobox**");
this.ListDirectory(treeView2, **unsure how to reference directory from combobox**");
}
And here's my treeview backend:
private void ListDirectory(TreeView treeView, string path)
{
treeView.Items.Clear();
var rootDirectoryInfo = new DirectoryInfo(path);
treeView.Items.Add(CreateDirectoryNode(rootDirectoryInfo));
}
private static TreeViewItem CreateDirectoryNode(DirectoryInfo directoryInfo)
{
var directoryNode = new TreeViewItem { Header = directoryInfo.Name };
foreach (var directory in directoryInfo.GetDirectories())
directoryNode.Items.Add(CreateDirectoryNode(directory));
foreach (var file in directoryInfo.GetFiles())
directoryNode.Items.Add(new TreeViewItem { Header = file.Name });
return directoryNode;
}
As far as the "Duplicate thread" comment, I think that's not the case. The link refers to datagrid selections. My question is regarding combobox selection whose items have multiple properties. My question was how to pull multiple properties from the same selection in XAML.