In your ViewModel define a property like:
public IEnumerable<string> Names
{
get
{
return nameColumn.Split('|');
}
}
Then bind your ComboBox ItemsSource to Names
Ok, the ViewModel will look like:
public class MainViewModel
{
private string contentNames = "test1|test2|test3";
public IEnumerable<string> SplitContentNames
{
get
{
return contentNames.Split('|');
}
}
}
The XAML will look like:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<ComboBox ItemsSource="{Binding SplitContentNames}"/>
</Grid>
And the code behind of MainViewWindow.cs will bind the DtaContext like so:
this.DataContext = new MainViewModel();
Then to get the selected item into your view model, add a property for your selected item:
public string SelectedName
{
get;
set;
}
and then bind the SelectedValue using XAML:
<ComboBox ItemsSource="{Binding SplitContentNames}" SelectedValue="{Binding SelectedName}"/>
Now when you change the value in the combobox the current value will be set in the SelectedName property.