I was hoping someone can help me figure this issue out. The combox seems to only list an item as individual characters when the binding source only has one value. If it is two or more, it lists the items properly.
Here's are two links with people experiencing similar issues. Link 1 Link 2
<DataTemplate>
<ComboBox ItemsSource="{Binding 'Clusters'}"
SelectedItem="{Binding Path='TargetCluster', Mode=TwoWay}"
Width="145"
/>
Here's the item source
$vCenters = @()
Foreach ($vCenter in $VDIEnvironments) {
$vCenter |
Add-Member -MemberType NoteProperty -Name TargetCluster -Value (
$clusters | ? VCName -like $vCenter.Name
)[0].Name -Force
$vCenter |
Add-Member -MemberType NoteProperty -Name Clusters -Value $(
$clusters | ? VCName -like $vCenter.Name
).Name -Force
$vCenter |
Add-Member -MemberType NoteProperty -Name TargetDatastore -Value $(
$datastores | ? VCName -like $vCenter.Name | Sort-Object -Descending FreeSpaceMB
)[0].Name -Force
$vCenter |
Add-Member -MemberType NoteProperty -Name Datastores -Value $(
$datastores | ? VCName -like $vCenter.Name
).Name -Force
$vCenter |
Add-Member -MemberType NoteProperty -Name TargetPortgroup -Value (
$portgroups | ? VCName -like $vCenter.Name | Sort-Object -Descending NumPorts
)[0].Name -Force
$vCenter |
Add-Member -MemberType NoteProperty -Name Portgroups -Value $(
$portgroups | ? VCName -like $vCenter.Name
).Name -Force
$vCenters += $vCenter
}
Filling the datagridvie
$SelectedVCenters = $VCenters |
Where-Object Env -like $WPFboxEnvironment.Text |
Where-Object Datastores -ne $Null
$SelectedVCenters | ForEach-Object {
$WPFboxSrcVCenter.Items.Add($_.Name)
$WPFlistTgtVCenters.Items.Add($_)
$WPFlistTgtVCenters.SelectedItems.Add($_)
}
ItemsControl.ItemsSource
to astring
. TheItemsControl
usually accesses the collection bound to theItemsSource
by index, because it has to create a container for each data item (ItemContainerGenerator
) in order to render the data as aVisual
object. Sincestring
implements an indexer likepublic char this[int index] { get; }
, it is accessible by index like a collection or an array. – BionicCodestring
toItemsControl.ItemsSource
, the internalItemContainerGenerator
treats thestring
value like a collection and accesses it by index. Because of the indexer, thestring
will return its underlying characters. – BionicCodestring
, but never to astring
directly to avoid this behavior. – BionicCode