Reputation: 2270
I have a method that takes a ComboBoxItem Name and creates an expander with a header based on the name of that ComboBoxItem. Shown below.
private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var selectedItem = combobox.SelectedItem as ComboBoxItem;
if (selectedItem != null)
{
string name = selectedItem.Name;
Expander expander = new Expander {Header = name};
}
}
I would like to then open a file dialog in order to select files and have the sub-value of the Expander set to the name of the file selected. Code with file dialog combined with above code shown below.
private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var selectedItem = combobox.SelectedItem as ComboBoxItem;
if (selectedItem != null)
{
string name = selectedItem.Name;
Expander expander = new Expander {Header = name};
Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
dlg.DefaultExt = ".xlsm";
dlg.Filter = "Excel Files (*.xlsx) | *.xlsx";
Nullable<bool> result = dlg.ShowDialog();
if (result == true)
{
//not sure what to do here, something like this maybe?
//this.expander.?subvalue? = dlg.FileName;
}
}
}
I know I can use anything as the sub-value, like a label or anything, but I'm not sure how to attach that to the newly created expander. Thanks
Upvotes: 1
Views: 362
Reputation: 2207
I am not sure if I understand what you're looking for but there is no SubValue
property for the expander. may be what you're looking for is the Content
property.
this.expander.Content = new TextBlock(){Text=dlg.FileName};
Upvotes: 1